Search code examples
vbacolorsvisio

How to convert MSOTINT colors to RGB in Visio VBA?


I want to write a macro for Visio that converts all occurrences of one color into another, such as RGB(255,128,0) to RGB(200,128,60), if I want to tone down some bright orange.

When I list the colors of the shapes in the page, using the formula shp.CellsU("Fillforegnd").Formula or shp.CellsU("Fillforegnd").FormulaU I most often get values like "THEMEGUARD(RGB(255;128;0))", that I can use to test and modify if appropriate.

But sometimes the value is something like "MSOTINT(RGB(255;255;255);-5)" . How can I obtain the RGB equivalent of the color of such shapes? The color values I am looking for are those I would obtain in the UI by clicking Fill... > More colors.

I tried shp.CellsU("Fillforegnd") that returns an integer, for example 34 or 24, but I could not find a way of converting that into RGB.

Here is the listing function I have got so far (inspired by VBA Change the Color of a Rounded Rectangle in Visio) :

Sub list_colors()
    For Each shp In ActivePage.Shapes
        Debug.Print (shp.CellsU("Fillforegnd").Formula)
        Debug.Print (shp.CellsU("Fillforegnd"))
    Next
End Sub

and here is an example of the output, for a page with 2 identical shapes, one set as a standard color, the other as a custom color:

THEMEGUARD(MSOTINT(RGB(255;255;255);-50))
 24 
THEMEGUARD(RGB(127;127;127))
 24 

Solution

  • Use ResultStr instead of Formula to get the value of a cell instead of formula:

    shape.CellsU("FillForegnd").ResultStr("")