Hide page if there are no visible layers

Started by diwakaramit, April 12, 2022, 04:21:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

diwakaramit

Hello I am trying to write a macro that will hide the page if there are no visible layers. So far i have come up with this

Line 1    Public Sub ShowHidepage()
Line 2    Dim aPage As Visio.Page, aLayer As Visio.Layer
Line 3    Dim c As Integer
Line 4   Dim flg As Boolean
Line 5    For Each aPage In ActiveDocument.Pages
Line 6      For Each aLayer In aPage.Layers
Line 7       If aLayer.CellsC(visLayerVisible).FormulaU = 1 Then
Line 8      flg = True
Line 9       End If
Line 10       Next
Line 11      If flg = False Then
Line 12       aPage.CellsSRC(visSectionObject, visRowPage, visPageUIVisibility).FormulaU = 1
Line 13     Else
Line 14       aPage.CellsSRC(visSectionObject, visRowPage, visPageUIVisibility).FormulaU = 0
Line 15       End If
Line 16     Next
Line 17    End Sub

But i keep getting error "Run-time error '438' Object does not support this property or method on Line 12. Can you please suggest me the path forward?

Thank you







diwakaramit

Just a quick update. I foud the correct function. The code below works fine

Public Sub ShowHidepage()
  Dim aPage As Visio.Page, aLayer As Visio.Layer
  Dim c As Integer
  Dim flg As Boolean
  For Each aPage In ActiveDocument.Pages
    For Each aLayer In aPage.Layers
      If aLayer.CellsC(visLayerVisible).FormulaU = 1 Then
      flg = True
      End If
    Next
      If flg = False Then
      aPage.PageSheet.CellsU("UIVisibility").FormulaU = 1
      Else
      aPage.PageSheet.CellsU("UIVisibility").FormulaU = 0
      End If
  Next
End Sub

Paul Herber

flg needs to be set to false before you start the layers loop!
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/