Author Topic: Layers and Displaying Layers  (Read 668 times)

0 Members and 1 Guest are viewing this topic.

Steveak

  • Newbie
  • *
  • Posts: 2
Layers and Displaying Layers
« on: July 31, 2019, 10:56:45 AM »
Hi All

Apologies if this is the incorrect forum

I am creating layers within my diagram with no problems, what i can't seem to get functioning is that i have multiple toggle buttons to the layers to display them. What happens is i want to view button 3 layer but this wont display unless i view button 1 and 2

Is there something i am doing wrong here? I am pretty new to this and have very basic VBA code. The code i am using is: -

Private Sub ToggleButton1_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 = "Layer1" Then
            Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
            If ToggleButton1.Value Then
                LayerCellObj.Formula = True Or 1
            Else
                LayerCellObj.Formula = False Or 0
            End If
        End If
    Next
End Sub

In addition, what would be good would also be able to have a button to toggle all on/off (display/hide) the layers

Thanks

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3799
  • Ideas Visio-lized into solutions
Re: Layers and Displaying Layers
« Reply #1 on: July 31, 2019, 11:31:02 AM »
Code has some syntax errors.

I swapped out your toggle button for simple test as proof of concept.
Code
Sub Macro1()

    Dim LayersObj As Visio.Layers
    Dim LayerObj As Visio.Layer
    Dim LayerName As String
    Dim layVis As Boolean
   
'    Set vsoLayer1 = ActivePage.Layers.Item("Yellow")
'    vsoLayer1.CellsC(visLayerVisible).FormulaU = "0"


    Set LayersObj = ActivePage.Layers
        For Each LayerObj In LayersObj
            LayerName = LayerObj.Name
            If LayerName = "Yellow" Then
                layVis = LayerObj.CellsC(visLayerVisible).ResultStr(visNone)
'                If ToggleButton1.Value Then
                If layVis = "0" Then           'replace this line with the above (uncomment)
                    LayerObj.CellsC(visLayerVisible).FormulaU = "1"
                Else
                    LayerObj.CellsC(visLayerVisible).FormulaU = "0"
                End If
            End If
        Next
End Sub

Visio 2019 Pro

Steveak

  • Newbie
  • *
  • Posts: 2
Re: Layers and Displaying Layers
« Reply #2 on: August 01, 2019, 03:36:11 AM »
Hi wapperdude

Thanks for the above

I tried the below and i couldn't get it to work. Sorry, sort of new to this. I went into Developer > View Code > Toggle Button 2 and amended to the below but when i clicked the button, nothing appeared or dissapeared

Thanks