visio How can i find traverse a flowchart in vba

I have a simply workflow in visio I would like to, on the press of a button, to

1) Find out what shapes I have
2) What is connected to each of the shapes.

in vba.

I have added an example of the diagram which i would ike to be able to traverse
Drawing1.vsd
peter3244Asked:
Who is Participating?
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
Though it seems like this should be an obvious feature of Visio --  it's not. There is no innate knowledge of "connectedness" in any version of Visio up to and including Visio 2007. It is possible to determine connectivity using code  but it's not as easy as you'd think.

For example, the Visio  drawing below contains macro code to determine what is at each end of  every line on the page. I created this code in response to another EE  question.  In that case, the user's goal was to produce a report showing the text  of the shapes at each end of every line. To make that possible the code  creates two shape data fields on each line and stores the text of each  endpoint shape in those fields. (NOTE: "shape data" was called "custom  properties" prior to Visio 2007)

To see how it works, open the  attached drawing in Visio, then open the Shape Data Window (View>Shape  Data Window). Before you run the macro, click on a couple of the  existing lines and you'll see that there is no shape data. Then run the  macro (Tools>Macro>ThisDocument>GetFlowchartConnections).  Now when you click on each line you'll see the text of the endpoint  shapes stored in fields called "From" and "To".

Now that each connector knows what it's connected to, you have several options for displaying the data. For example, you could write more VBA code to display the data in the Visio drawing or do something else with it. Or if you'd like a very simple but effective alternative, you can use the Visio report wizard to create a report on this data (Visio 2003: Tools>Reports   Visio 2007: Data>Reports)

If you want to get even more sophisticated, there is sample code in the Visio SDK for navigating a Visio drawing.  However, rather than start with the SDK directly, here's an excellent article on path analysis that incorporates and expands on the SDK code:



Determine-flowchart-paths-PROP.vsd
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
I forgot to mention that Visio 2010 incorporates the idea of "connectedness" for the first time. So if you're using Visio 2010, the above code will still work, however there are more efficient ways to get the job done.

Regards,
Scott
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.