Originally Posted by
Bob Phillips
Not sure I will be able to help, I am pretty raw with the Visio OM, but if you could post an example workbook and an idea what the output would look like, I will have a shot at it.
I have given up trying to extract the comment associated with the shape. I realize now the comment is considered another shape. Instead, I manually entered the same number I numbered the shape with at the start of the comment, so I can match them later in Excel. For example, if I numbered the shape 5.2.1, then the comment will start with "5.2.1".
So I now generate two files, one with only "process" shape data, and one with the comment data.
The only issue I have is that it only works on the active page, despite adding in the For each page in the active document code. Maybe I am missing something. If I can get that to work, I am good to go. Because I do the loop twice, the first time for the shapes, and the second time for the comments, I need to make sure I start back at the first page for each loop through the document. Any suggestions?
Sub ShapeInfoToFile()
Dim strPath As String
strPath = ActiveDocument.Path
Dim MyFile As String
MyFile = strPath & "E2EArchWG Visio Shape Report"
MyFile2 = strPath & "E2EArchWG Visio Comment Report"
Open MyFile For Output As #2
Open MyFile2 For Output As #3
Dim vDoc As Visio.Document
Dim vShape As Visio.Shape
Dim vComments As Visio.Comments
Dim vShapeLink As Hyperlink
Dim vPage As Visio.Page
Dim Entry As String
Dim sText As String
Set vDoc = Visio.ActiveDocument
' Loop through shapes creating a string containing them all, writing to file
For Each Page In vDoc.Pages
Set vPage = Visio.ActivePage
For Each Shape In vPage.Shapes
Set vShape = Shape
If Not vShape.Master Is Nothing Then
' Select only Process shapes
If vShape.Master.NameU = "Process" Then
' Get Page Name
Entry = vPage.Name
' Get shape displayed text
Entry = Entry + "," + vShape.Text
' Loop through the shape Hyperlinks
For Each vShapeLink In vShape.Hyperlinks
Entry = Entry + "," + vShape.Hyperlinks.Item(0).Description + "," + vShape.Hyperlinks.Item(0).Address
Next vShapeLink
' Append shape comment
' Entry = Entry + "," + vShape.Comments
Write #2, Entry
End If
End If
Next
Next
'Loop through comments creating a string containing them all
For Each Page In vDoc.Pages
Set vPage = Visio.ActivePage
For Each vComment In vPage.Comments
sText = vPage.Name + "," + vComment.Text
Write #3, sText
Next
Next
End Sub