Visio VBA Help with Coloring Containers

Copper Contributor

Hello,

 

 I'm teaching myself VBA for Visio to automate a Program Milestone Report. I've run into a problem when coloring a container. I can see that the settings were established in the VBA code, but they are not taking effect in the diagram. The following picture shows the selected container is still a solid white, but the fill and transparency setting show the correct values.

 

 

When I bump the transparency value to 11, the color and transparency kick in right away. The change is shown in the next picture.

 

 

The code to set and color the container is as follows:

 

Dim vsoDoc1 As Visio.Document
Dim theContainerShape As Visio.Shape

 

Set vsoDoc1 = Application.Documents.OpenEx(Application.GetBuiltInStencilFile(visBuiltInStencilContainers, visMSUS), visOpenHidden)
Set theContainerShape = ActivePage.DropContainer(vsoDoc1.Masters.ItemU("Plain"), vsoSelection)
With theContainerShape
.Text = wrksname
.CellsSRC(visSectionObject, visRowFill, visFillForegndTrans).FormulaU = "10.000002384186%"
.CellsSRC(visSectionObject, visRowFill, visFillBkgndTrans).FormulaU = "10.000002384186%"
.CellsSRC(visSectionObject, visRowGradientProperties, visRotateGradientWithShape).FormulaU = "FALSE"
.CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaForceU = "THEMEGUARD(RGB(254,229,153))"
'.CellsSRC(visSectionObject, visRowFill, visFillBkgnd).FormulaForceU = "THEMEGUARD(SETATREF(User.FillForegndIn,,1)+SETATREF(User.FillPatternIn,SETATREFEVAL(FillPattern),1)+IF(User.CStyle=4,Sheet.2179!User.HColor4,IF(User.CStyle=11,1,Sheet.2179!User.HColor2)))"
.CellsSRC(visSectionObject, visRowFill, visFillPattern).FormulaForceU = "1"
.CellsSRC(visSectionObject, visRowFill, visFillForegndTrans).FormulaU = "10.000002384186%"
.CellsSRC(visSectionObject, visRowFill, visFillBkgndTrans).FormulaU = "10.000002384186%"
.CellsSRC(visSectionObject, visRowGradientProperties, visFillGradientEnabled).FormulaForceU = "FALSE"
.CellsSRC(visSectionObject, visRowGradientProperties, visRotateGradientWithShape).FormulaU = "FALSE"
.CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "THEMEGUARD(RGB(254,229,153))"
.CellsSRC(visSectionObject, visRowFill, visFillPattern).FormulaU = "1"
.CellsSRC(visSectionObject, visRowFill, visFillForegndTrans).FormulaU = "10.000002384186%"
.CellsSRC(visSectionObject, visRowFill, visFillBkgndTrans).FormulaU = "10.000002384186%"
.CellsSRC(visSectionObject, visRowGradientProperties, visFillGradientEnabled).FormulaU = "FALSE"
.CellsSRC(visSectionObject, visRowGradientProperties, visRotateGradientWithShape).FormulaU = "FALSE"

 

 

Would appreciate the help to get the container color and transparency implemented without having to manually bump a setting for the change to take place. 

 

Let me know if you need more details, and thanks in advance for your help.

 

Have a great day!

 

Will

1 Reply

OK, so doing my own investigation, and a bunch of trial and errors. I've discovered a way to get the color and effects I wanted for the container. After the container is dropped, snag it's ID. Because the container is a grouping of shapes, there are additional shape details that need to be modified. So, snag the ID to a variable and then add the appropriate increment for the sub-shape that needs to be modified.

 

If anyone has found another way, please let me know.