Connector Custom Properties

J

joegarber

I want to use vba to insert the text of each connected shape to a
custom property of the connector. My code looks good except for the
part where I try to access the custom property of the connector, as
with the following snippet:

Set visCell = visConnect.Cells("prop.name")
visCell.Formula = StringToFormulaForString(strOut)

As the debugger happily points out, there's no such thing as .Cells for
a Visio.Connect, even though there is for a Visio.Shape. Isn't there
some way to do this? Thanks
 
A

Al Edlund

is there a custom property "name"?
al
ps you might consider calling it something else since name is used in a lot
of contexts'
 
J

joegarber

Yes, there is a custom property called "name".
The problem is that there doesn't appear to be a .Cells option for the
connector, the way there is for a shape. Is there?
 
A

Al Edlund

How is visConnect defined / assigned? As an object you should be able to
check it's custom properties by looking at it's shapesheet.

al
 
J

joegarber

Here's the code so you can see what I mean.
On a side note, for some reason strOut is only capturing the hyphen and
the ToCell text -- not the FromCell text. But that's a separate
problem...

Sub SaveConnections()

Dim visPage As Visio.Page
Dim visConnects As Visio.Connects
Dim visConnect As Visio.Connect
Dim visCell As Visio.Cell
Dim intI As Integer
Dim intLayerCt As Integer
Dim strOut As String

Set visPage = Application.ActivePage
Set visConnects = visPage.Connects

For Each visConnect In visConnects
strOut = visConnect.FromCell.Shape.Text & " - "
strOut = strOut & visConnect.ToCell.Shape.Text
If visConnect.CellExists("Prop.Name", False) Then
Set visCell = visConnect.Cells("prop.name")
visCell.Formula = StringToFormulaForString(strOut)
End If
Next

End Sub
 
A

Al Edlund

I'd suggest you get a copy of the visio sdk (available over on msdn for
free). It has examples on connections in vb which should port fairly easily
to what you want to do.
al
 
J

joegarber

I got it working... using the sdk a bit, but I didn't get too much help
from that. Mostly I fixed it by printing things to a file to see what
was going wrong.

I don't really understand one thing, though. From what the sdk said, I
thought FromSheet returns the shape on one end of the connector, and
ToSheet returns the shape on the other end. But it turned out that
FromSheet referred to the connector itself, and ToSheet returns one of
the shapes; I then had to advance to the "next" connector and call its
ToSheet to get the second shape connected. That doesn't seem right to
me really, but it works.

Here's the final product, for anyone interested. The text of the two
connected shapes are separated by the "~" symbol.

'Saves the text of connected shapes in the custom properties
'of the connector
Sub SaveConnections()

Dim visPage As Visio.Page
Dim visConnects As Visio.Connects
Dim visConnect As Visio.Connect
Dim visCell As Visio.Cell
Dim intI As Integer
Dim strOut As String

Set visPage = Application.ActivePage
Set visConnects = visPage.Connects

For intI = 1 To visConnects.Count
Set visConnect = visConnects(intI)
strOut = visConnect.ToSheet.Text
intI = intI + 1
If intI <= visConnects.Count Then
Set visConnect = visConnects(intI)
strOut = strOut & " ~ " & visConnect.ToSheet.Text
End If
If visConnect.FromSheet.CellExists("Prop.Name", False) Then
Set visCell = visConnect.FromSheet.Cells("prop.name")
visCell.Formula = StringToFormulaForString(strOut)
End If
Next

End Sub
 
M

Mark Nelson [MS]

A Connects object is not a shape. It is a collection of Connect objects
which keep track of the glue relationships between shapes. Each Connect
object represents a single connection. If a connector shape is glued at
both ends then it has two Connect objects in its Connects collection.

To find out what a connector shape is glued to, you start with the Shape
object for the connector. Then you get its Connects property. Then you can
iterate through the Connect objects in the Connects collection. On each
Connect object the ToSheet property returns the Shape object that the
connector end is glued to. The FromSheet property is always the connector
itself.

So assuming that your connector is glued to shapes at each end, those shapes
are found by:
ConnectorShape.Connects(1).ToSheet and ConnectorShape..Connects(2).ToSheet

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

joegarber

Thanks for the info Mark, that's exactly what I needed. Makes a lot
more sense now!

Here's the revision of the code in my last post, so no one uses the
code that resulted from my confusion...

'Saves the text of connected shapes in the custom properties
'of the connector
Sub SaveConnections()

Dim visPage As Visio.Page
Dim visShapes As Visio.Shapes
Dim visShape As Visio.Shape
Dim visCell As Visio.Cell
Dim strOut As String

Set visPage = Application.ActivePage
Set visShapes = visPage.Shapes

For Each visShape In visShapes
If visShape.Cells("ObjType") = 2 Then
strOut = visShape.Connects(1).ToSheet.Text & " ~ "
strOut = strOut & visShape.Connects(2).ToSheet.Text
If visShape.CellExists("Prop.Name", False) Then
Set visCell = visShape.Cells("Prop.Name")
visCell.Formula = StringToFormulaForString(strOut)
End If
End If
Next

End Sub
 
J

joegarber

btw, in my case it's safe to assume that every connector is connecting
two shapes, hence no check of visShape.Connects.Count
 

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