Visio VBA - 如何获取状态形状的标题和副标题(UML)

时间:2017-01-06 14:40:35

标签: vba uml state diagram visio

我想从状态(UML Standard Stencil)中获取形状信息。你可以在图片中看到标题" Aktiv"和" Eintritt /"我不知道从哪里得到这个变量。

UML example

编辑: 为了说清楚,我不知道如何从Visio中的UML形状中获取信息。这是一个示例代码:

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 个答案:

答案 0 :(得分:0)

好的,我找到了一个解决方案,但我不知道是否有更好的解决方案。

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

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

因此状态形状实际上包含两个形状,因此您可以从第1项或第2项中获取信息。