Visio VBA - How do I get the title and subtitle of a state shape (UML)

421 views Asked by At

I want to get the shape information out of a state (UML Standard Stencil). You can see in the picture the title "Aktiv" and "Eintritt/" etc. I have no clue where to get this as a variable.

UML example

Edit: To make it clear, I don't know how I can get the information out of a UML shape in Visio. Here is an example code:

Private Sub test()
Dim s As Shape
Dim vsoPage As Visio.Page
Dim getStateName As String 
'I need the name for example "Aktiv" from the state 
'and the name of the "Sub" information as "Eintritt" etc.

Set vsoPage = ThisDocument.Pages(1)
For Each s In vsoPage.Shapes
    getStateName = s.????
Next s

End Sub
1

There are 1 answers

0
Philipp Mochine On

Okay I found a solution, I don't know if there is a nicer one though.

Private Sub test()
  Dim s As Shape
  Dim vsoPage As Visio.Page
  Dim getStateTitle As String
  Dim getStateSubTitle As String

Set vsoPage = ThisDocument.Pages(1)

For Each s In vsoPage.Shapes
  If Contains(s) = False Then
    'Not a Stateshape
  Else
    getStateTitle = getStateTitle & s.Shapes.Item(1).Text & vbCrLf
    getStateSubTitle = getStateSubTitle & s.Text & vbCrLf
  End If
Next s
End Sub

with

Public Function Contains(s As Shape) As Boolean
Dim DummyString As String
On Error GoTo err
  Contains = True
  DummyString = s.Shapes.Item(1)
  Exit Function
err:
  Contains = False
End Function

So the state shape contains actually two shapes thus you can get the information from Item 1 or 2.