How to get displayed text from each page through vba or c#?

Started by bsbn, November 04, 2023, 04:10:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bsbn

Hi,

Through shape report utility in visio, i can able to extract the displayed text from all pages. (Attached snap)

How i can get these displayed texts through programming c# or vba?

Thanks.

threatcon

Hello,

You can try either of the subs below. One captures all the info as a User Defined Type and places them into an array. The other is a little more simpler and just grabs the shape text only.
I verified both subs work.


Option Explicit
Type ShapeInfo
DisplayedText As String
ShapeID As Long
ShapeName As String
End Type
Sub Main()
    Dim Pages As Visio.Pages, Page As Visio.Page, shp As Visio.Shape, ShapeNameList() As ShapeInfo, ShapeStuff As ShapeInfo, Count As Long
   
    Count = 0
    Set Pages = Visio.ActiveDocument.Pages
    For Each Page In Pages
        For Each shp In Page.Shapes
            ReDim Preserve ShapeNameList(Count)
            ShapeStuff.DisplayedText = shp.Text
            ShapeStuff.ShapeID = shp.ID
            ShapeStuff.ShapeName = shp.Name
            ShapeNameList(Count) = ShapeStuff
            Count = Count + 1
        Next
    Next

End Sub

'The easy version
Sub EasyMain()
    Dim Pages As Visio.Pages, Page As Visio.Page, shp As Visio.Shape, ShapeNameList() As String, ShapeNameCollection As String
   
    Set Pages = Visio.ActiveDocument.Pages
    For Each Page In Pages
        For Each shp In Page.Shapes
            If ShapeNameCollection = "" Then
                ShapeNameCollection = shp.Text
            Else
                ShapeNameCollection = ShapeNameCollection & "," & shp.Text
            End If
        Next
    Next
ShapeNameList = Split(ShapeNameCollection, ",")
End Sub