Change Line Color of Box in Org Chart using VBA

Started by aman, April 18, 2015, 03:11:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aman

I have an org chart where I want to color the box boundary lines based on a parameter available in the shape data.

I have tried to use following command and can see that the new value gets applied in the shape sheet, but the color of the visible box doesn't change.
vsoShape.CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(RGB(0,32,96))"

When, I tried recording a macro, seemingly Visio is applying this property at a nested level within the shape.
    Application.ActiveWindow.Page.Shapes.ItemFromID(21).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(THEMEVAL(""VariantColor6""))"
    Application.ActiveWindow.Page.Shapes.ItemFromID(21).Shapes.ItemFromID(22).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(THEMEVAL(""VariantColor6""))"
    Application.ActiveWindow.Page.Shapes.ItemFromID(21).Shapes.ItemFromID(22).Shapes.ItemFromID(27).Shapes.ItemFromID(29).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(THEMEVAL(""VariantColor6""))"
    Application.ActiveWindow.Page.Shapes.ItemFromID(21).Shapes.ItemFromID(22).Shapes.ItemFromID(27).Shapes.ItemFromID(28).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(THEMEVAL(""VariantColor6""))"
    Application.ActiveWindow.Page.Shapes.ItemFromID(21).Shapes.ItemFromID(22).Shapes.ItemFromID(23).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(THEMEVAL(""VariantColor6""))"
    Application.ActiveWindow.Page.Shapes.ItemFromID(21).Shapes.ItemFromID(22).Shapes.ItemFromID(23).Shapes.ItemFromID(25).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(THEMEVAL(""VariantColor5""))"

It is the last red colored item that is actually applying the color change; all previous ones have no effect. Seemingly the org chart shape is composite and the box is the shape id 25.

Need help in being able to access this nested box.

I tried writing a nested loop using the shapes object of the shape. The code takes to some nested hierarchy but is not able to access this particular nested object saying its locked.

Any help will be much appreciated as the objective is to use different box line color for different level of boxes in the org chart.

Thanks

Yacine

#1
Hi Aman,
beside that the line of code cannot be applied as it is, there is the special difficulty that your code would need to identify the right sub-shape (the frame). This is not a trivial task.
I would suggest that you modify the shape in a way that the aimed field references a field in the top most parent.
In the top-parent shape you would add a custom property "prop.frameColour"
In the shapesheet of the frame you would write in the line color field "shape.XXX!prop.frameColour". XXX being the ID of the top-parent shape. This ID is displayed in the drawing explorer and in the shape's shapesheet.
Now your code will just need to modify the proper "prop.frameColour" field.
shp.CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(THEMEVAL(" & chr(34) &"VariantColor5" & chr(34) & "))".
Mind the chr(34) in the code, which will add correctly the quotation marks.

Regards
Yacine