自动连接visio形状时,有时会出现VBA运行时错误,但有时却不会

问题描述

我有一个很大的程序,但是它的作用是扫描数据表并使用该信息创建图表。一旦放置了所有符号,它就会返回并使用我编写的此函数将其连接,该函数的工作方式是放置一个连接器,然后将其形状表的开始x和结束x部分更改为两个对象的连接点行连接。宏将正常运行,完成所有连接而不会出现问题,然后随机地通过Run-time error '-2032465768 ...并说“发生了异常”。我不明白的是,它正确地将连接器放置在同一张图的相似部分上,当我查看两个对象的形状表时,它们的连接点已定义。另外,它有时在我运行它时偶尔发生,有时当我重新运行它时,它在先前遇到异常的那部分效果很好。

这是错误消息:

enter image description here

连接两个对象的功能是:

Sub ConnectShapes(Diagram As clsNewDiagram,Shape1 As Visio.Shape,Shape1ConnectionNum,Shape2 As Visio.Shape,Shape2ConnectionNum,Optional Color As Integer = LineColor.BLACK)
    Dim Connector As Visio.Shape
    Set Connector = Diagram.CurrentPage.Drop(Diagram.Document.Masters.ItemU("Dynamic connector"),0#,0#)
    Dim vsoCell1 As Visio.Cell
    Dim vsoCell2 As Visio.Cell
    Set vsoCell1 = Connector.CellsSRC(visSectionObject,visRowXForm1D,vis1DBeginX)
    Set vsoCell2 = Shape1.CellsSRC(visSectionConnectionPts,0)
    vsoCell1.@R_502_6454@eto vsoCell2
    Set vsoCell1 = Connector.CellsSRC(visSectionObject,vis1DEndX)
    Set vsoCell2 = Shape2.CellsSRC(visSectionConnectionPts,0)
    vsoCell1.@R_502_6454@eto vsoCell2
    Connector.SendToBack
    
    'Connector.CellsSRC(visSectionObject,visRowShapeLayout,visSLOLineRouteExt).FormulaU = "2" ' For curved connector.
    'Connector.CellsSRC(visSectionObject,visSLOConFixedCode).FormulaU = "3"
    
    If Color = LineColor.FIBER Then
        Connector.CellsSRC(visSectionObject,visRowLine,visLineColor).FormulaU = "THEMEGUARD(RGB(255,255))"
    ElseIf Color = LineColor.DC Then
        Connector.CellsSRC(visSectionObject,102,0))"
    ElseIf Color = LineColor.RET Then
        Connector.CellsSRC(visSectionObject,visLineColor).FormulaU = "THEMEGUARD(RGB(0,202,0))"
    End If     
End Sub

当我按debug时,它不喜欢这条线,但是可以在其他符号上使用

开启

enter image description here

这是其输出图片,您可以看到它成功地连接了其他符号,而且我完全不知道为什么它突然经历了这个错误,这是以前不习惯的。

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)