为Microsoft Visio 2013/16自动检测形状的已连接邻居的类型

时间:2019-06-23 04:34:00

标签: vba shapes visio visio-vba

我创建了自己的主形状列表,并将其放在VSS文件中。 有一个形状连接器可以连接其余的连接器。 此连接器的“操作”部分有几行。

我浏览了许多站点,但是对于根据连接形状的类型检测连接事件并从“操作”部分调用所需行的可能性一无所获。

我还没有找到任何可以描述邻居或现有连接的部分或VBA函数。

想法是更改连接器参数以显示正确的连接类型。

1 个答案:

答案 0 :(得分:0)

  

我创建了自己的主形状列表并将其放在VSS文件中

您现在真的应该使用.vssx!

  

我浏览了许多站点,但未发现检测连接事件的可能性。...

在此ThisDocument级别上没有用于添加连接的事件,但在应用程序级别上有一个事件。
因此,您可以将应用程序对象添加到ThisDocument并监听它的事件。 这可能会导致无法预料的内存泄漏,因为它引用了它的父对象! Description here
也许其他人可以对此有所了解...

ThisDocument背后的代码中:

Option Explicit

Private WithEvents vsApp As Visio.Application


Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
    OnStart
End Sub

Private Sub Document_BeforeDocumentClose(ByVal doc As IVDocument)
    OnStop
End Sub

Public Function Kickstart()
    'Call this function to restart in case the program stops
    OnStart
End Function

Private Sub OnStart()
    Set vsApp = Me.Application
End Sub

Private Sub OnStop()
    Set vsApp = Nothing
End Sub


Private Sub vsApp_ConnectionsAdded(ByVal Connects As IVConnects)
   If Not Connects.Document Is Me.DocumentSheet Then Exit Sub 'make sure only to listen to events happening in this document
    Dim connect As connect
    For Each connect In Connects
        Debug.Print "Added Connection: ", connect.FromSheet & " To " & connect.ToSheet
    Next connect
End Sub
Private Sub vsApp_ConnectionsDeleted(ByVal Connects As IVConnects)
   If Not Connects.Document Is Me.DocumentSheet Then Exit Sub 'make sure only to listen to events happening in this document
    Dim connect As connect
    For Each connect In Connects
        Debug.Print "Deleted Connection: ", connect.FromSheet & " To " & connect.ToSheet
    Next connect
End Sub
  

...并根据所连接形状的类型从“操作”部分调用所需的行

要找到连接类型/形状,有很多可能性。 我的定位方法是在形状中使用用户定义的单元格来识别它们/检查它们是否应引起动作。从那里开始,您可以使用选择案例块。

  

我还没有找到任何可以描述邻居或现有连接的部分或VBA函数。

由于您可以对它们应用过滤器,因此后两个特别有趣。