我想突出显示与特定组相对应的形状。以下代码仅突出显示与活动页面或母版分组的形状,而不与活动页面中存在的组分组的形状。
Sub CA_Trace_Conflict1()
PCC_CA = InputBox("Enter PCC Band")
'SCC1_CA = InputBox("Enter SCC1 Band")
Dim shp As Visio.Shape
Dim subshp As Visio.Shape
Dim connectorshape As Visio.Shape
Dim BandLinewidth As String
Dim lngShapeIDs() As Long
Dim count As Integer
Dim PCC_Flag As Integer
Dim SCC1_Flag As Integer
PCC_Flag = 0
SCC1_Flag = 0
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Dim UndoScopeID1 As Long
PCC_CA_space = PCC_CA & " "
For Each shp In Visio.ActivePage.shapes
If shp.Type = 2 Then 'Check if shp is a group
For Each subshp In shp.shapes
If InStr(shp.Text, PCC_CA_space) > 0 Then
'If PCC_CA Like shp.Text Then
Set connectorshape = shp
Debug.Print shp.Parent
Application.ActiveWindow.Page.shapes.ItemFromID(shp.ID).CellsSRC(visSectionObject,visRowLine, visLineWeight).FormulaU = "5.5 pt"
' Debug.Print shp.ID
End If
Next
End If
Next
End Sub
我想您想以编程方式在组中选择子形状。在Visio中这样做并不明显,所以请允许我帮助。我将在my website上放置指向两篇文章的链接,并在文章末尾添加与Microsoft的一篇文章的链接。这些将进一步讨论与选择相关的主题。
所以让我们解决您的问题...
设置
您现在在此页面上具有三个形状。
您已经发现,您可以通过编程方式选择这样的组:
Public Sub SelectGroup()
'// Get the active window:
Dim win As Visio.Window
Set win = Visio.ActiveWindow
'// Deselect everything:
Call win.DeselectAll
'// Get a shape object:
Dim shp As Visio.Shape
Set shp = Visio.ActivePage.Shapes.ItemFromID(3) '<<----- Sheet.3 is the group!
'// Cause that shape to be selected in the window:
Call win.Select(shp, Visio.VisSelectArgs.visSelect)
'// Cleanup:
Set shp = Nothing
Set win = Nothing
End Sub
顺便说一句,上面的Sub比必须的要挑剔得多,而且要长得多。但是,当您开始添加功能和行为时,使事情简单明了将很有帮助。实际上,您可以像这样单行完成整个过程,甚至可以将其粘贴到“即时”窗口中:
Call Visio.ActiveWindow.Select(Visio.ActivePage.Shapes.ItemFromID(3), Visio.VisSelectArgs.visDeselectAll + Visio.VisSelectArgs.visSelect)
现在子选择Sheet.1或Sheet.2。有人认为我们可以简单地将shp对象更改为子形状之一,ala:
'// Sheet.1 is a subshape, you'll get an error
Set shp = Visio.ActivePage.Shapes.ItemFromID(1) '<<----- ID = 1
但是这行不通。实际上,您会收到“此操作不合适的目标对象”错误。
要解决此问题,我们必须将不同的参数传递给Select方法:
Public Sub SelectSubshape()
'// We've drawn two rectangles on a blank page, then
'// grouped them. Sheet.1 and Sheet.2 are subshapes,
'// Sheet.3 is the group.
'// Get the active window:
Dim win As Visio.Window
Set win = Visio.ActiveWindow
'// Deselect everything:
Call win.DeselectAll
'// Get a subshape object:
Dim shp As Visio.Shape
Set shp = Visio.ActivePage.Shapes.ItemFromID(2)
'// Cause that shape to be SUBSELECTED in the window.
'// Note the different argument: visSubSelect
Call win.Select(shp, Visio.VisSelectArgs.visSubSelect) ' <<------ visSubSelect!
'// Cleanup:
Set shp = Nothing
Set win = Nothing
End Sub
Voila!在活动窗口中选择的子形状!
如果要检测已经选择了哪些形状,则必须摆弄Selection对象的IterationMode属性。这非常令人困惑,而且我不认为您现在正在要求这样做。但是知道该术语将有助于您在将来需要时寻求帮助。
文章
Getting a Handle on Selecting and Subselecting Visio Shapes