Show/Hide Layers

Started by evancarroll, July 17, 2008, 02:29:05 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

evancarroll

I have a form which contains four check boxes, one for each layer that I wish to hide or show across all pages.  This is the code I wrote/gathered, it compiles perfectly, but doesn't seem to work.  Any help would be appreciated.

All of these subs are included in the code for the form.


Private Sub Submit_Click()
Dim LayerName As String
Dim LayerString As String
Dim LayerString2 As String
Dim LayerIndex As Integer
Dim PageToIndex As Visio.Page

If (CheckDev.Value = 1) Then
    ' define the layer to turn on
    LayerName = "Annotations.Development"
    Call TurnOn
End If
If (CheckCopy.Value = 1) Then
    ' define the layer to turn on
    LayerName = "Annotations.Copy"
    Call TurnOn
End If
If (CheckDesign.Value = 1) Then
    ' define the layer to turn on
    LayerName = "Annotations.Design"
    Call TurnOn
End If
If (CheckQuestion.Value = 1) Then
    ' define the layer to turn on
    LayerName = "Annotations.Question"
    Call TurnOn
End If
If (CheckDev.Value = 0) Then
    ' define the layer to turn on
    LayerName = "Annotations.Development"
    Call TurnOff
End If
If (CheckCopy.Value = 0) Then
    ' define the layer to turn on
    LayerName = "Annotations.Copy"
    Call TurnOff
End If
If (CheckDesign.Value = 0) Then
    ' define the layer to turn on
    LayerName = "Annotations.Design"
    Call TurnOff
End If
If (CheckQuestion.Value = 0) Then
    ' define the layer to turn on
    LayerName = "Annotations.Question"
    Call TurnOff
End If
frmAnnotations.Hide
End Sub



Private Sub TurnOff()

' loop through all the pages you have and set the layer invisible
For Each PageToIndex In Application.ActiveDocument.Pages

    LayerIndex = -1
    ' find layer index
    For i = 1 To Application.ActiveDocument.Pages(PageToIndex.Index).Layers.Count
        If Application.ActiveDocument.Pages(PageToIndex.Index).Layers(i).Name = LayerName Then
            LayerIndex = i
        End If
    Next
    LayerString = "Layers.Visible[" + Format(LayerIndex) + "]"
    LayerString2 = "Layers.Print[" + Format(LayerIndex) + "]"
   
    If LayerIndex <> -1 Then
        Debug.Print LayerString
        Set ACell = Application.ActiveDocument.Pages(PageToIndex.Index).PageSheet.Cells(LayerString)
        ACell.Formula = "=0"
        Set ACell = Application.ActiveDocument.Pages(PageToIndex.Index).PageSheet.Cells(LayerString2)
        ACell.Formula = "=0"
    End If
Next

End Sub



Private Sub TurnOn()

' loop through all the pages you have and set the layer invisible
For Each PageToIndex In Application.ActiveDocument.Pages

    LayerIndex = -1
    ' find layer index
    For i = 1 To Application.ActiveDocument.Pages(PageToIndex.Index).Layers.Count
        If Application.ActiveDocument.Pages(PageToIndex.Index).Layers(i).Name = LayerName Then
            LayerIndex = i
        End If
    Next
    LayerString = "Layers.Visible[" + Format(LayerIndex) + "]"
    LayerString2 = "Layers.Print[" + Format(LayerIndex) + "]"
   
    If LayerIndex <> -1 Then
        Debug.Print LayerString
        Set ACell = Application.ActiveDocument.Pages(PageToIndex.Index).PageSheet.Cells(LayerString)
        ACell.Formula = "=1"
        Set ACell = Application.ActiveDocument.Pages(PageToIndex.Index).PageSheet.Cells(LayerString2)
        ACell.Formula = "=1"
    End If
Next

End Sub

evancarroll

Turns out I just needed to make the variables global.
-e

Visio Guy

Thanks for the code sample, then  ;D
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010