How would I attach a Data Graphic to a shape in Visio, Using VBA?

J

James

I am attempting to use VBA to have Visio attach a data Graphic to some shapes
I have on a page. I had tried this code
Visio.ActiveWindow.Selection.DataGraphic =
Visio.ActiveDocument.Masters("Data Graphic 2")

But, that does not work.
 
S

sbmack7

I don't believe you can assign a Selection of objects to a
DataGraphic. Rather you have to loop through the Selection and assign
the DG individually. E.g,

Dim visShape as Shape

For Each visShape in ActiveWindow.Selection
visShape.DataGraphic = ActiveDocument.Masters("Data Graphic 2")
Next

For Each looping is a good practice no matter what. Because almost
everything is a Shape in Visio. So when you start Selecting stuff you
may net objects you don't want. For Each allows you to insert a Shape
check to ensure you only operate on the ones you want.

SteveM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top