我正在尝试做最简单的事情 - 使用带有 GlueTo 的宏在 visio 中连接两个 2d 形状。我已经删除了两个形状,用“In”和“Out”添加到它们的连接点。现在,当我尝试用鼠标连接它们时 - 一切正常。然后我录制了一个宏:
Sub Macro1()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("1")
ActiveWindow.DeselectAll
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(1), visSelect
Application.ActiveWindow.Selection.Move -1.161417, 0.669291
Dim vsoCell1 As Visio.Cell
Dim vsoCell2 As Visio.Cell
Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsU("PinX")
Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(15).CellsSRC(7, 0, 0)
vsoCell1.GlueTo vsoCell2
Dim vsoCell3 As Cell
Dim vsoCell4 As Cell
Set vsoCell3 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionConnectionPts, 0, 0)
Set vsoCell4 = Application.ActiveWindow.Page.Shapes.ItemFromID(15).CellsSRC(visSectionConnectionPts, 0, 0)
vsoCell3.GlueTo vsoCell4
Application.EndUndoScope UndoScopeID1, True
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
而且它不起作用...如果我解开这些形状并运行录制的宏,它将抛出“此操作的源对象不合适”
我该如何解决?