Hello, everyone,
I am looking for a macro with which I can get all connectors directly into the foreground. Online I found the following code, but it did not help:
Sub SendConnectorsToBack_ByLayer()
// Get the active page:
Dim pg As Visio.Page
Set pg = Visio.ActivePage
// Get the connectors layer:
// Note, ItemU should work for non-English Visio
Dim lyr As Visio.Layer
Set lyr = pg.Layers.ItemU("Connector")
// Get a selection of connectors, by layer:
Dim sel As Visio.Selection
Set sel = pg.CreateSelection( _
visSelTypeByLayer, visSelModeSkipSub, lyr)
// Send the selection to back:
If (sel.Count > 0) Then
Call sel.SendToBack
End If
End Sub
Trying to select over all connectors and then bring them to the foreground and record them does not help:
Sub Macro8()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
ActiveWindow.DeselectAll
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(614), visSelect
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(615), visSelect
Application.ActiveWindow.Selection.BringToFront
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
With this version the problem remains that the individual shapes are addressed via ItemID. Unfortunately this changes frequently
cheers ty
I haven't tested this, but try something like this:
Sub BringConnectorsToFront_ByLayer()
'// Get the active page:
Dim vsoPage As Visio.Page
Set vsoPage = Visio.ActivePage
'// Get the connectors layer:
'// Note, ItemU should work for non-English Visio
Dim vsoLayer As Visio.Layer
Set vsoLayer = vsoPage.Layers.ItemU("Connector")
'// Get a selection of connectors, by layer:
Dim vsoSelection As Visio.Selection
Set vsoSelection = vsoPage.CreateSelection( _
visSelTypeByLayer, visSelModeSkipSub, vsoLayer)
Dim i As Integer
For i = 1 To vsoSelection.Count
Dim vsoShape As Visio.Shape
Set vsoShape = vsoSelection(i)
Call vsoShape.bringToFront
Next i
End Sub
This code assumes your connector's use Visio's default "Connector" layer
Using the macro recorder and stripping out the non-essential lines:
Sub Macro1()
Dim vsoSelection1 As Visio.Selection
Dim shp As Visio.Shape
Set vsoSelection1 = ActiveWindow.Page.CreateSelection(visSelTypeByLayer, visSelModeSkipSuper, "Connector")
ActiveWindow.Selection = vsoSelection1
ActiveWindow.Selection.BringToFront
For Each shp In vsoSelection1 'Do whatever you need within the For ... Next block. Example colors lines blue and makes them thicker.
shp.CellsU("LineColor").FormulaU = "RGB(0,0,255)"
shp.CellsU("LineWeight").FormulaU = "3 pt"
Next
End Sub