Is there a way to access shapes while in "edit master shape" window?

Started by freshlychurnedbutter, February 07, 2022, 10:43:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

freshlychurnedbutter

I currently editing a master shape and I want to parse through the shapes within this master shape.

With the help of some wonderful people on this forum I was able to put together the following script

Dim FullFileName As String
Dim shp As Shape

FullFileName = "C:\Users\Documents\My Shapes\Test Stencil.vssx"
Set StnObj = Documents.Open(FullFileName)

For Each shp In StnObj.Masters.Item("TEST SHAPE").Shapes
If shp.CellExists("User.TestCell", visExistsAnywhere) Then
shp.Cells("User.TestCell").FormulaU = "ID()"
End If
Next shp
StnObj.Save
StnObj.Close
Set StnObj = Nothing

This makes Visio open the "Test Stencil" file, locate the master named "TEST SHAPE" and index through the shapes inside it. It then sets the cell "User.TestCell" to the formula "ID()", saves the stencil and closes it.

However, I am trying to access the shapes while I am editing the master shape. I tried running this while having the edit master shape opened.

Dim shp As Shape
For Each shp In ActiveDocument.Shapes
If shp.CellsExists("User.TestCell", visExistsAnywhere) Then
shp.Cells("User.TestCell").FormulaU = "ID()"
End If
Next shp

When I run the code, I get the "Object doesn't support this property or method" error at the 2nd line.

Is it possible to point VBA into this "active document"? Is it called something else that I'm not referencing properly?

wapperdude

You can update the master in the Doc stencil with your updated master.  From the stencil, right click icon and copy.
Next, open Doc stencil, and open desired master shape for editing.  In the edit window, delete the master shape and then paste the new copy.  Save and close window.

The doc master has now been updated, and changes flushed up into respective drawing shapes.

You may want to test this on a simple file, and also create a backup copy before doing this on your "real" file.
Visio 2019 Pro

wapperdude

Using macro recorder, here macro for the indicated steps...

For my test case, i edited the stencil master by changing its fillforegnd from red to blue.
My stencil is Stencil2, and the master is Master.4


Sub MasterUpdate()

    Documents.Item("Stencil2").Masters.ItemFromID(4).Open.OpenDrawWindow
    Windows.ItemEx("Stencil2:Stencil:Master.4").Activate

    ActiveWindow.Master.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "THEMEGUARD(RGB(0,176,240))"
    ActiveWindow.Master.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowFill, visFillBkgnd).FormulaU = "THEMEGUARD(SHADE(FillForegnd,LUMDIFF(THEMEVAL(""FillColor""),THEMEVAL(""FillColor2""))))"
    ActiveWindow.Master.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowGradientProperties, visFillGradientEnabled).FormulaU = "FALSE"
    ActiveWindow.Master.Close

    Documents.Item("Drawing1").Masters.ItemFromID(6).Open.OpenDrawWindow
    Windows.ItemEx("Drawing1:Stencil:Master.6").Activate

    ActiveWindow.DeselectAll
    ActiveWindow.Select Application.ActiveWindow.Master.Shapes.ItemFromID(5), visSelect
    ActiveWindow.Selection.DeleteEx (visDeleteNormal)
    ActiveWindow.Master.Paste
    ActiveWindow.Master.Close

End Sub

Visio 2019 Pro

Yacine

Yacine