Question

How does one create specific shapes in microsoft visio that are selectable through the normal interface? I am looking for code like ActivePage.addShape(type: person, 100,100, 50,50)

The msdn and visio help documentation comes across as a bit advanced for a beginner, but is it the case that one has to add a shape manually and then give it an id through vba which can be understood and used again. Or do you have to create a global sub/class and then refer to objects that you have given names to.

Was it helpful?

Solution

The function you need is called Drop. The first argument is dropObject, which can be a reference to another shape, the current selected shape, or a Master object from a Visio stencil.

You can try this out to see how it works:

Dim ShpObj As Visio.Shape
Set ShpObj = ActivePage.Drop(ActiveWindow.Selection, 100, 50)

So, using ActiveWindow.Selection means Visio will duplicate the selected shape and put it at 100, 50.

To get a Master, you need to first find the stencil document that holds the master. Here's an example, putting a Triangle shape from the Basic Shapes block diagram stencil:

Dim ShpObj As Visio.Shape
Set ShpObj = ActivePage.Drop(Application.Documents("BASIC_U.VSS").Masters("Triangle"))

Setting the result of the Drop function to ShpObj means you can refer to it later in code. Otherwise there is a Shapes collection in the Page class that contains all the shapes in the page.

Hopefully that'll make a good start for you in programming in Visio VBA.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top