Show/Hide Layers across pages

B

Bostich

Okay so I can record a macro that will show or hide a layer. Now is there
someone who can give me the VBA code to modify it to :

A) Toggle show/hide, so for exampe CTRL+T hdies layer, then CTRL+T shows it
again

and

B) Will do this automatically throughout an entire document.

thanks.
me.
 
D

David Parker [Visio MVP]

I recorded the following to turn off the "Flowchart" layer:

Sub Macro1()

Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Layer Properties")
Dim vsoLayer1 As Visio.Layer
Set vsoLayer1 = Application.ActiveWindow.Page.Layers.Item(1)
vsoLayer1.CellsC(visLayerVisible).FormulaU = "0"
vsoLayer1.CellsC(visLayerPrint).FormulaU = "0"
Application.EndUndoScope UndoScopeID1, True
End Sub

Then I copied the above and amended to run over all pages in the documnet as
follows:

Sub Macro2()

Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Layer Properties")
Dim vsoLayer1 As Visio.Layer
Dim vsoPage As Visio.Page

For Each vsoPage In Application.ActiveDocument.Pages
For Each vsoLayer1 In vsoPage.Layers
If vsoLayer1.Name = "Flowchart" Then
vsoLayer1.CellsC(visLayerVisible).FormulaU = "0"
vsoLayer1.CellsC(visLayerPrint).FormulaU = "0"
Exit For
End If
Next vsoLayer1
Set vsoLayer1 = Nothing
Next vsoPage
Set vsoPage = Nothing
Application.EndUndoScope UndoScopeID1, True

End Sub

Of course, you could create parameterised sub functions to pass through the
layer name , and on (1) or off (0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top