R
revans00
Hello,
I have an existing Visio (2002) drawing with several shapes (rectangles)
connected by line (Dynamic connectors). I would like to extract a simple
text list for each Dynamic connector, the name (actual object text
label) of the rectangles on either end.
I've created some code which does walk through the shapes in the
activepage, and have tried to use some sample code from various sources
(ie: http://visio.mvps.org/VBA.htm), but can't quite get it to work.
Can anyone help please?
TIA!
Richard
Public Sub ListObjs()
'Declare object variables as Visio object types.
Dim intCounter As Integer
Dim intShapeCounter As Integer
Dim vsoPage As Visio.Page
Dim vsoDocument As Visio.Document
Dim vsoDocuments As Visio.Documents
Dim vsoPages As Visio.Pages
Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim groupedShapes As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim vsoConnectToCell As Visio.Cell
Dim i As Integer
Dim PosX As Double, PosY As Double
Dim ShapeX As Double, ShapeY As Double
' Set vsoShapes = ActivePage.Shapes
Set vsoShapes = ActiveDocument.Pages.Item(1).Shapes
For intShapeCounter = 1 To vsoShapes.Count
' This code seems to get me closer, but not close enough!
'Get the next shape.
Set vsoShape = vsoShapes.Item(intShapeCounter)
Set vsoConnects = vsoShape.Connects
Debug.Print "Name: "; vsoShape.Name
Debug.Print "ID : "; vsoShape.ID
Debug.Print "Type: "; vsoShape.Type
If vsoShape.CellExists("Prop.Row_1.Label", 1) Then
Debug.Print "Val : ";
vsoShape.Cells("Prop.Row_1.Value").ResultStr(0)
Debug.Print "Val : ";
vsoShape.Cells("Prop.Row_2.Value").ResultStr(0)
End If
'For each connection, get the cell it connects to.
For intCounter = 1 To vsoConnects.Count
Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectToCell = vsoConnect.ToCell
'Print connect information in the Immediate window.
Debug.Print " To "; vsoConnectToCell.LocalName
Next intCounter
' This code didn't give me results that looked valuable
' Set vsoShape = Visio.ActivePage.Shapes(intShapeCounter)
' nrows = vsoShape.RowCount(Visio.visSectionConnectionPts)
' Debug.Print "#"; intShapeCounter; " "; vsoShape.Name; "
connections ="; nrows
' If nrows > 0 Then
' ShapeX = vsoShape.CellsSRC(Visio.visSectionObject,
visRowXFormOut, visXFormPinX).Result(Visio.visNone)
' ShapeX = ShapeX - vsoShape.CellsSRC(Visio.visSectionObject,
visRowXFormOut, visXFormLocPinX).Result(Visio.visNone)
' ShapeY = vsoShape.CellsSRC(Visio.visSectionObject,
visRowXFormOut, visXFormPinY).Result(Visio.visNone)
' ShapeY = ShapeY - vsoShape.CellsSRC(Visio.visSectionObject,
visRowXFormOut, visXFormLocPinY).Result(Visio.visNone)
' For i = 0 To nrows - 1
' PosX = ShapeX +
vsoShape.CellsSRC(Visio.visSectionConnectionPts, i,
visX).Result(Visio.visNone)
' PosY = ShapeY +
vsoShape.CellsSRC(Visio.visSectionConnectionPts, i,
visY).Result(Visio.visNone)
' Debug.Print PosX; " "; PosY
' Next i
' End If
Next intShapeCounter
I have an existing Visio (2002) drawing with several shapes (rectangles)
connected by line (Dynamic connectors). I would like to extract a simple
text list for each Dynamic connector, the name (actual object text
label) of the rectangles on either end.
I've created some code which does walk through the shapes in the
activepage, and have tried to use some sample code from various sources
(ie: http://visio.mvps.org/VBA.htm), but can't quite get it to work.
Can anyone help please?
TIA!
Richard
Public Sub ListObjs()
'Declare object variables as Visio object types.
Dim intCounter As Integer
Dim intShapeCounter As Integer
Dim vsoPage As Visio.Page
Dim vsoDocument As Visio.Document
Dim vsoDocuments As Visio.Documents
Dim vsoPages As Visio.Pages
Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim groupedShapes As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim vsoConnectToCell As Visio.Cell
Dim i As Integer
Dim PosX As Double, PosY As Double
Dim ShapeX As Double, ShapeY As Double
' Set vsoShapes = ActivePage.Shapes
Set vsoShapes = ActiveDocument.Pages.Item(1).Shapes
For intShapeCounter = 1 To vsoShapes.Count
' This code seems to get me closer, but not close enough!
'Get the next shape.
Set vsoShape = vsoShapes.Item(intShapeCounter)
Set vsoConnects = vsoShape.Connects
Debug.Print "Name: "; vsoShape.Name
Debug.Print "ID : "; vsoShape.ID
Debug.Print "Type: "; vsoShape.Type
If vsoShape.CellExists("Prop.Row_1.Label", 1) Then
Debug.Print "Val : ";
vsoShape.Cells("Prop.Row_1.Value").ResultStr(0)
Debug.Print "Val : ";
vsoShape.Cells("Prop.Row_2.Value").ResultStr(0)
End If
'For each connection, get the cell it connects to.
For intCounter = 1 To vsoConnects.Count
Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectToCell = vsoConnect.ToCell
'Print connect information in the Immediate window.
Debug.Print " To "; vsoConnectToCell.LocalName
Next intCounter
' This code didn't give me results that looked valuable
' Set vsoShape = Visio.ActivePage.Shapes(intShapeCounter)
' nrows = vsoShape.RowCount(Visio.visSectionConnectionPts)
' Debug.Print "#"; intShapeCounter; " "; vsoShape.Name; "
connections ="; nrows
' If nrows > 0 Then
' ShapeX = vsoShape.CellsSRC(Visio.visSectionObject,
visRowXFormOut, visXFormPinX).Result(Visio.visNone)
' ShapeX = ShapeX - vsoShape.CellsSRC(Visio.visSectionObject,
visRowXFormOut, visXFormLocPinX).Result(Visio.visNone)
' ShapeY = vsoShape.CellsSRC(Visio.visSectionObject,
visRowXFormOut, visXFormPinY).Result(Visio.visNone)
' ShapeY = ShapeY - vsoShape.CellsSRC(Visio.visSectionObject,
visRowXFormOut, visXFormLocPinY).Result(Visio.visNone)
' For i = 0 To nrows - 1
' PosX = ShapeX +
vsoShape.CellsSRC(Visio.visSectionConnectionPts, i,
visX).Result(Visio.visNone)
' PosY = ShapeY +
vsoShape.CellsSRC(Visio.visSectionConnectionPts, i,
visY).Result(Visio.visNone)
' Debug.Print PosX; " "; PosY
' Next i
' End If
Next intShapeCounter