VBS to change layer properties on multiple pages

Started by jik_ff, June 01, 2012, 05:05:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jik_ff

Is this possible?

I have a Visio 2007 floor plan map that has multiple pages (1 per floor).  I have a layer (and will be adding more) that shows department colors per office.  This is not always needed so I have a Command button that turns it off or on. 

Private Sub CommandButton1_Click()
Dim LayersObj As Visio.Layers
Dim LayerObj As Visio.Layer
Dim LayerName As String
Dim LayerVisable As Visio.Cell
Dim LayerPrint As Visio.Cell
Set LayersObj = ActivePage.Layers
For Each LayerObj In LayersObj
    LayerName = LayerObj.Name
    ' Debug.Print LayerName
    If LayerName = "BackColor" Then
        Set LayerVisable = LayerObj.CellsC(visLayerVisible)
        Set LayerPrint = LayerObj.CellsC(visLayerPrint)
        If LayerVisable.Formula = False Or 0 Then
            LayerVisable.Formula = True Or 1
            LayerPrint.Formula = True Or 1
        Else
            LayerVisable.Formula = False Or 0
            LayerPrint.Formula = False Or 0
        End If
    End If
Next
End Sub


To be honest, I'm new to visio's higher functions, shapesheets and vbs/macros.  So if I'm looking at this from the wrong angle please let me know.  What I am hoping is that I can make this change happen across all pages.  I assume that I may be able to alter the :
Set LayersObj = ActivePage.Layers
to a loop that goes through all pages, but I'm having a hard time finding the proper syntax.  The help is not much... help...

Thanks in advance.

nashwaan

To iterate through all pages of the document, you can use:


Dim PageObj as Visio.Page
For Each PageObj in ActiveDocument.Pages
    ...
Next


Therefore, the full code can be written as:

Private Sub CommandButton1_Click()
    Dim PageObj As Visio.Page
    Dim LayerObj As Visio.Layer
    For Each PageObj In ActiveDocument.Pages
        For Each LayerObj In PageObj.Layers
            If LayerObj.Name = "BackColor" Then
                LayerObj.CellsC(visLayerVisible).Formula = IIf(LayerObj.CellsC(visLayerVisible).ResultIU, 0, 1)
                LayerObj.CellsC(visLayerPrint).Formula = LayerObj.CellsC(visLayerVisible).Formula
            End If
        Next
    Next
End Sub


Hope this helps,
Yousuf.
Give me six hours to chop down a tree and I will spend the first four sharpening the axe — Abraham Lincoln

jik_ff

:) Thanks!  :)

Also, thanks for the shortcuts.  I'm a bit new to visio programming and VB.