Using Selection

J

John... Visio MVP

Hi Sachin.

The carriage returns are the key as I have discovered using this code
as well. Also, the msg box issue was fixed after I fooled around with
it a bit. I ended up just hard coding a loop through the shapes I was
working with.

I am experiencing a related problem, however. I want to find explicit
connections as in ShapeA connects with ShapeB etc... using the actual
shape text. The ToSheet command is returning a shape text, however the
FromSheet command is returning the text of a connector, not a shape.
Does anyone know of another command that will return the shape text on
the other side of the connector?

Thanks,

Damascus


When normal humans like us look at a Visio drawing we see Shape A connected
to Shape B. When Visio looks at the same drawing it sees Shape A connected
to a connector shape and the connector shape connected to Shape B.

So you will have to check the From/To connections of the connector to find
Shape B. You may also want to verify that the shape ShapeA is connected to
is a 1d shape (typical for most connections).

John... Visio MVP
 
V

vespasiandamascus

Hi John. I am using this piece of code to access the information I am
trying to get:
Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoShapeTo As Visio.Shape
Dim vsoConnectWith As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intShapeIndex As Integer
Dim intConIndex As Integer
Dim intCounter As Integer
Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intShapeIndex = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intShapeIndex)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet
Set vsoConnectWith = vsoConnect.FromSheet
Set vsoShapeTo = vsoConnectWith.FromConnects 'I added
this as an experiment right now, give a compilation error (mismatch)

Debug.Print vsoConnectTo.Text; " connects with "; vsoShapeTo.Text
Debug.Print " "

---

I won't bore you with the loop close statements etc... this is the
important part anyways. It seems like I AM using the connector and not
the shape for FromSheet and ToSheet. I tried that last bit of code to
see if that would use the connnector as opposed to the shape, but I
got the mismatch. Do you have any suggestions?

Greatly appreciated,
Damascus
 
J

John... Visio MVP

Hi John. I am using this piece of code to access the information I am
trying to get:
Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoShapeTo As Visio.Shape
Dim vsoConnectWith As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intShapeIndex As Integer
Dim intConIndex As Integer
Dim intCounter As Integer
Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intShapeIndex = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intShapeIndex)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet
Set vsoConnectWith = vsoConnect.FromSheet
Set vsoShapeTo = vsoConnectWith.FromConnects 'I added
this as an experiment right now, give a compilation error (mismatch)

Debug.Print vsoConnectTo.Text; " connects with "; vsoShapeTo.Text
Debug.Print " "

---

I won't bore you with the loop close statements etc... this is the
important part anyways. It seems like I AM using the connector and not
the shape for FromSheet and ToSheet. I tried that last bit of code to
see if that would use the connnector as opposed to the shape, but I
got the mismatch. Do you have any suggestions?

Greatly appreciated,
Damascus


You have to be careful with your apples and oranges. vsoShapeTo is a Visio
shape, but FromConnects is a Connection collection.

So you will have to loop through the connections:
Set vsoConnects = vsoShape.FromConnects

'For each connection, get the shape it connects to.
For Each vsoConnect In vsoConnects

'Print the name of the shape the
'Connect object connects to.
Debug.Print vsoShape.Name; " is connected from "; vsoConnect.FromSheet.Name

Next vsoConnect


John... Visio MVP
 
V

vespasiandamascus

I thought I incorporated the nested loop correctly, but I am still
getting the same results.

Here is how i did it:

Public Sub MasterConnectivityList()

Dim vsoShapes As Visio.Shapes
Dim vsoShapeA As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoConnectWith As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intCurrentShapeIndex As Integer
Dim intCounter As Integer
Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intCurrentShapeIndex = 1 To vsoShapes.Count

Set vsoShapeA = vsoShapes(intCurrentShapeIndex)
Set vsoConnects = vsoShapeA.Connects

'Loop through connects
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet

********************************************************************************
Loop through connects, getting the shape they connect with
For Each vsoConnect In vsoConnects
Set vsoConnectWith = vsoConnect.FromSheet
Next vsoConnect

********************************************************************************
'Print the name of the shape the
'Connect object connects to.
Debug.Print vsoConnectTo.Text; " connects with ";
vsoConnectWith.Text
Debug.Print " "

Next intCounter

Next intCurrentShapeIndex

End Sub
 
V

vespasiandamascus

Does it not seem there like it is looping through the connections? I
am confused now. Thanks for sticking with me and all of your help
John.

Damascus
 

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