Loopin through Layers and skip a layer for if condition

Started by diwakaramit, May 09, 2022, 12:49:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

diwakaramit

Hello I am novice to VBA so please excuse me if the question is too simple.

I am writing set of codes on a Visio file that has multiple pages and each pages has many layer but one common layer called "P&ID". One of the code i am writing is to loop through each page starting from page 2 and loop through each layers and if there are no visible layers then hide the page. But when looping through layers i dont want to check the condition for visibility on "P&ID" layer (because this layer will always be on). I wrote this code but did not work and i know i made this complicated.

Public Sub ShowHidepage()
  Dim flg As Boolean
  Dim pag As Integer
  Dim j As Integer
  Dim c As Integer
  Set flg=false
   pag = ActiveDocument.Pages.Count
   For j = 2 To pag
   c = 1
    Do While ActiveDocument.Pages(j).Layers(c) <> "P&ID"
   If ActiveDocument.Pages(j).Layers(c).CellsC(visLayerVisible).FormulaU = "1" Then
             flg = True
            Exit Do
        Else
          flg = False
               End If      
              c = c + 1
    Loop
            If flg = True Then
ActiveDocument.Pages(j).PageSheet.CellsSRC(visSectionObject, visRowPage, visPageUIVisibility).FormulaU = "1"
     Else
        ActiveDocument.Pages(j).PageSheet.CellsSRC(visSectionObject, visRowPage, visPageUIVisibility).FormulaU = "0"
End If
Next j
End Sub

Yacine

"did not work" is a very poor diagnosis.


Public Sub ShowHidePage()


    Dim pg As Page
    Dim lyr As Layer
    Dim b_visible As Boolean
   
    For Each pg In ActiveDocument.Pages
        If pg.Index <> 1 Then
            b_visible = False
            For Each lyr In pg.Layers
                If lyr.Name <> "P&ID" Then
                    If lyr.CellsC(visLayerVisible).ResultIU = 1 Then
                        b_visible = True
                        Exit For
                    End If
                End If
            Next lyr
            If b_visible Then
                pg.PageSheet.Cells("UIVisibility").Formula = 0
            Else
                pg.PageSheet.Cells("UIVisibility").Formula = 1
            End If
        End If
    Next pg


End Sub
Yacine