Author Topic: How to change shape foreground color of a shape that is part of a grouped shape  (Read 765 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 1
I have this situation I cannot find a solution with my current knowledge. I've been programming excel VBA for some years now and just entered into the Visio VBA world (Fascinating)
I have a Visio diagram to manage my processes. I created a stencil with shapes for each symbol in my diagram. Some of these shapes are grouped shapes, i.e. I have a rectangle with another rectangle on top (Header) where the ID and Title of the process will be displayed. 

Programatically (VBA) I've been able to export Visio shape data (item class and ID) to TXT, read this TXT in Excel and parse my process database to assembly based on the provided parameters the right information for the shape.  Thus far I've done all for all icons that I manage.  Still, there is a requirement on this grouped rectangle that I cannot fulfill: the header square needs to be colored to a specific number based on the Shape ID. I was able to do this on a non grouped rectangle, so I think it is possible to do. 

Set celObj = shpObj.Cells("FillForegnd")
celObj.FormulaU = "THEMEGUARD(RGB(" & intCarrier(0) & "," & intCarrier(1) & "," & intCarrier(2) & "))"

where intCarrier 0 to 2 host the RGB values that I receive as a parameter from Excel

In Visio I do this by clicking twice (slow click) on the shape: the first click selects the group, the second click selects the top rectangle I am referring to (named HeadBar in the Shape Data window)

My question is: How do I select the HeadBar shape to apply THEMEGUARD(RGB(X,Y.Z)) to it?


M. Iannini


  • Jr. Member
  • **
  • Posts: 12
    • AIGS GraFiS-Tactic
As i correctly understand you there are two ways:
1 - get shape as item in group
2 - get any shape directly by it's ID

Dim shp As Visio.Shape
Const mainShapeID = 10
Const targetShapeID = 9

    'Select shape by order in main group
    Set shp = Application.ActivePage.Shapes.ItemFromID(mainShapeID).Shapes(1)
    'Select shape directly
    Set shp = Application.ActivePage.Shapes.ItemFromID(targetShapeID)
    shp.Cells("FillForegnd").FormulaU = "RGB(0,0,255)"
And may be from the darkness something beautiful will rize