Set variable to master shape and make copies

How can assign a variable to a master shape on a stencil and then using that variable make copies of master shape in the active document?
mrandersAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Scott HelmersConnect With a Mentor Visio Consultant, Trainer, Author, and DeveloperCommented:
See whether the code below accomplishes what you need.

Two things you may do differently:

1) I've used the DockedStencils method to get the names of all docked stencils and then have used the first stencil in the list to get masters. You may know the name of the stencil you want to use or have another way to select one.

2) I've selected the first three masters in the stencil by index number. You may want to select them by name or some other criterion.
Sub DropShapesFromStencil()
 
    Dim stencil As Visio.Document, CurrentMaster As Visio.Master
    
    Dim arrStencilNames() As String
    ' get names of current docked stencils into array
    ActiveWindow.DockedStencils arrStencilNames
    
    ' get first stencil by name
    Set stencil = Documents.Item(arrStencilNames(0))
    
    ' drop one each of the first three masters in the stencil
    For i = 1 To 3
        Set CurrentMaster = stencil.Masters(i)
        ThisDocument.Pages(1).Drop CurrentMaster, 2 * i, 5
    Next i
 
End Sub

Open in new window

0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
Can you explain a little more about what you mean? For example, do you want a numeric data value in a master to trigger creation of that number of instances when the master is dragged onto the drawing page? Or did you have something else in mind?
0
 
mrandersAuthor Commented:
Hey Scott thanks, sorry for replying late. I was away.

Let's say I have three shapes in the master sheet 'master1', 'master2' and 'master3'. I want to set a variable 'currentMaster' to master1 and then use it to drop some intstances on the active document. Next I set it to master2 and drop some instances of y on the active document, then master3 etc. The point is to have a terse way to refer to and use master shapes when creating instances.
0
 
mrandersAuthor Commented:
Nice!
0
All Courses

From novice to tech pro — start learning today.