选择一个形状(例如正方形或更多正方形)后,粘在这个形状上的所有连接器都会突出显示红色,黄色。下面找到的代码对我不起作用,有什么建议吗? (我不是编码员,所以请耐心等待我)
Set shpAtEnd = cnx(1).ToSheet
' use HitTest to determine whether Begin end of connector
' is outside shpAtEnd
x = shpAtEnd.HitTest(shpTaskLink.Cells("BeginX"), _
shpTaskLink.Cells("BeginY"), 0.01)
If x = visHitOutside Then
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 2
Else
' do other stuff
End If
这是我在stackoverflow上的第一个答案,我希望以下VBA代码可以解决您如何在Visio中突出显示连接器或连接形状的问题!
Public Sub HighlightConnectedShapes()
Dim vsoShape As Visio.Shape
Dim connectedShapeIDs() As Long
Dim connectorIDs() As Long
Dim intCount As Integer
' Highlight the selected shape
Set vsoShape = ActiveWindow.Selection(1)
vsoShape.CellsU("Fillforegnd").FormulaU = "RGB(146, 212, 0)"
vsoShape.Cells("LineColor").FormulaU = "RGB(168,0,0)"
vsoShape.Cells("LineWeight").Formula = "2.5 pt"
' Highlight connectors from/to the selected shape
connectorIDs = vsoShape.GluedShapes _
(visGluedShapesAll1D, "")
For intCount = 0 To UBound(connectorIDs)
ActivePage.Shapes.ItemFromID(connectorIDs(intCount)).Cells("LineColor").FormulaU = "RGB(168,0,0)"
ActivePage.Shapes.ItemFromID(connectorIDs(intCount)).Cells("LineWeight").Formula = "2.5 pt"
Next
' Highlight shapes that are connected to the selected shape
connectedShapeIDs = vsoShape.connectedShapes(visConnectedShapesAllNodes, "")
For intCount = 0 To UBound(connectedShapeIDs)
ActivePage.Shapes.ItemFromID(connectedShapeIDs(intCount)).Cells("LineColor").FormulaU = "RGB(168,0,0)"
ActivePage.Shapes.ItemFromID(connectedShapeIDs(intCount)).Cells("LineWeight").Formula = "2.5 pt"
Next
End Sub
要运行宏,您可以考虑与形状的double-click behavior关联。
如果您只需要突出显示传入/传出连接器和传入/传出形状,请将visGluedShapesAll1D
替换为visGluedShapesIncoming1D
/ visGluedShapesOutgoing1D
,将visConnectedShapesAllNodes
替换为visConnectedShapesIncomingNodes
/ visConnectedShapesOutgoingNodes
。
在visgluedshapesflags和visconnectedshapesflags了解更多信息。祝好运!
以下代码将遍历所有1d-Shapes,粘贴到Selection中的第一个形状,并将其名称写入Immediate窗口。这应该是一个很好的起点。
如果选择了Shape(至少没有一些解决方法),Visio没有触发事件,因此可能将宏绑定到keybind。
visGluedShapesAll1D
标志可以替换为此处描述的另一个过滤器:Microsoft Office Reference
Sub colorConnectors()
If ActiveWindow.Selection(1) Is Nothing Then Exit Sub
Dim selectedShape As Shape
Set selectedShape = ActiveWindow.Selection(1)
Dim pg As Page
Set pg = ActivePage
Dim gluedConnectorID As Variant 'variant is needed because of "For Each" Loop
For Each gluedConnectorID In selectedShape.GluedShapes(visGluedShapesAll1D, "")
Debug.Print pg.Shapes.ItemFromID(gluedConnectorID).NameU
Next gluedConnectorID
End Sub