View Single Post
 
Old 12-03-2018, 04:33 PM
ivano ivano is offline Windows 10 Office 2013
Novice
 
Join Date: Dec 2018
Posts: 3
ivano is on a distinguished road
Default show or hide layers in all pages

Hi,
I have visio 2013 and have many pages with several layers. I have 3 layers that I want to show or hide through checkboxes. In one page I created three checkmark boxes and put together some code that will either hide or show a specific layer when it's corresponding checkmark box is either checked or unchecked. It works only for that one page. I want it to work on all pages in the document. As you can see below, I have it as three separate pieces of code but if there's a better way to combine it into one piece of code please feel free to mash it into one.
My code is:


Public Sub CheckBox1_Click()
Dim LayersObj As Visio.Layers
Dim LayerObj As Visio.Layer
Dim LayerName As String
Dim LayerCellObj As Visio.Cell

Set LayersObj = ActivePage.Layers
For Each LayerObj In LayersObj
LayerName = LayerObj.Name
If LayerName = "To Be Form" Then
Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
If CheckBox1.Value Then
LayerCellObj.Formula = True Or 1
Else
LayerCellObj.Formula = False Or 0
End If
End If
Next
End Sub


Public Sub CheckBox2_Click()
Dim LayersObj As Visio.Layers
Dim LayerObj As Visio.Layer
Dim LayerName As String
Dim LayerCellObj As Visio.Cell

Set LayersObj = ActivePage.Layers
For Each LayerObj In LayersObj
LayerName = LayerObj.Name
If LayerName = "SHC As Is Form" Then
Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
If CheckBox2.Value Then
LayerCellObj.Formula = True Or 1
Else
LayerCellObj.Formula = False Or 0
End If
End If
Next
End Sub



Public Sub CheckBox3_Click()
Dim LayersObj As Visio.Layers
Dim LayerObj As Visio.Layer
Dim LayerName As String
Dim LayerCellObj As Visio.Cell

Set LayersObj = ActivePage.Layers
For Each LayerObj In LayersObj
LayerName = LayerObj.Name
If LayerName = "Works As Is Form" Then
Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
If CheckBox3.Value Then
LayerCellObj.Formula = True Or 1
Else
LayerCellObj.Formula = False Or 0
End If
End If
Next
End Sub



I've attached a sample of the document too.


Thanks
Reply With Quote