I'm investigating how to automatically update a visio file created with one mastershape (v1.0.vssx) to the next version of the mastershape (v1.1.vssx). When updating each master shape, use Master.Name as the key.
With the code below, I was able to open the vsdx file and vssx and open their respective Masters.
vssx_Master = vssxMaster vsdx_shape.master = vssx_Master
I wondered if I could update the master shape with the code, but unfortunately vssxMaster is the same as vssxMaster.Name and its type is String. Is there a way to replace the Master of one shape with another?
not work...
Dim mastershape_dict As Object
Set mastershape_dict = CreateObject("Scripting.Dictionary")
Set vsoApp = CreateObject("Visio.Application")
Set vssxdoc = vsoApp.Documents.Item(1)
Set vssxMasters = vssxdoc.Masters
For Each vsoPage In vsoDoc.Pages
For Each vsoShape In vsoPage.Shapes
If Not (vsoShape.Master Is Nothing) Then
mastername = vsoShape.Master.Name
For Each vssxMaster In vssxMasters
mastershape_name = vssxMaster.Name
If mastername = mastershape_name Then
vsoShape.ReplaceShape (vssxMaster)
End If
Next
End If
Next
Next
I wondered if I could update the master shape with the code
CodePudding user response:
You dont need iterate all masters into stencil :)
For Each vsoPage In doc.Pages
For Each vsoShape In vsoPage.Shapes
If Not (vsoShape.Master Is Nothing) Then
vsoShape.ReplaceShape vssxMasters.Item(vsoShape.Master.Name)
End If
Next
Next
CodePudding user response:
You must iterate through all the shapes on the page. If the shape was created based on the master from stencil v.1.0, then replace it with the corresponding master v.1.1. using the ReplaceShape method
Sub ttt()
Dim sh As Shape
For Each sh In ActivePage.Shapes
If sh.Master.NameU = "Circle" Then sh.ReplaceShape Application.Documents.Item("BLOCK_M.vssx").Masters.ItemU("Diamond")
Next
End Sub