下午好, 我一直在尝试编写一个宏(VBA)来更改Visio中连接箭头的属性。由于某种原因,这些变化似乎没有发生。我录制了一个宏,然后根据我的需要对其进行了修改。
这是我一直在使用的代码:
Sub Macro1(shapeID As Long)
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Manual Edit")
Application.ActiveWindow.page.Shapes.ItemFromID(shapeID).CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaForceU = "GUARD(EndX-BeginX)"
Application.ActiveWindow.page.Shapes.ItemFromID(shapeID).CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaForceU = "GUARD(EndY-BeginY)"
Application.ActiveWindow.page.Shapes.ItemFromID(shapeID).CellsSRC(visSectionFirstComponent, 2, 0).FormulaForceU = "0.6024533433537" & " in"
Application.ActiveWindow.page.Shapes.ItemFromID(shapeID).CellsSRC(visSectionFirstComponent, 3, 0).FormulaForceU = "0.6024533433537" & " in"
Application.EndUndoScope UndoScopeID1, True
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
存在多个问题:
首先是子声明的语法。括号内的内容是错误的。如果这是一个独立的宏,则不应在其中输入任何内容。
对于独立模式,形状标识是通过在宏执行之前选择它来确定的。然后,添加这些代码行:
Dim vShp as Visio.Shape
Set vShp = ActiveWindow.Selection(1)
3)。将您的可执行行更改为 vShp.CellsSRC....
4)。保护宽度和高度的 2 条线可能是多余且不必要的。
5)。接下来的两行尝试控制连接器路由。忘了它。养猫更容易。然而,可能有合适的选择。请参阅此链接中的回复 8 和 9:http://visguy.com/vgforum/index.php?topic=1916.msg8680#msg8680