【问题标题】:Visio VBA - How do I get the title and subtitle of a state shape (UML)Visio VBA - 如何获取状态形状的标题和副标题 (UML)
【发布时间】:2017-05-21 08:25:42
【问题描述】:

我想从某个状态(UML 标准模板)中获取形状信息。你可以在图片中看到标题“Aktiv”和“Eintritt/”等。我不知道从哪里得到这个变量。

编辑: 为了清楚起见,我不知道如何从 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

【问题讨论】:

  • 您好,欢迎来到 Stack Overflow,这不是“我的代码”网站。请提供您的努力的证据,以便我们为您提供帮助。我建议你阅读How to Ask主题
  • 嘿@victor-moraes,谢谢你的评论。但是很抱歉,我没有正确解释。我不希望人们为我编码。我只想知道获取我寻求的信息的方法的名称是什么。我的示例代码看起来像这样(这真的没关系,但你要求它:) Test
  • 不确定你是否尝试用谷歌搜索,但this seems like a start
  • @VictorMoraes 谢谢你的帮助,但最重要的部分是读出形状的“上标题”。我只是得到“字幕”。
  • 根据您提供的答案,您似乎已经解决了问题:)

标签: vba uml state diagram visio


【解决方案1】:

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

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 中获取信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多