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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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?
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.
Scott HelmersVisio 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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mrandersAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Visio

From novice to tech pro — start learning today.