Toggle Visio Layers On and Off

I have 4 buttons(Commandbutton1. Commandbutton2, etc...) and 4 layers(Layer1, Layer2, etc..). I would like to use the buttons to toggle the visibility on and off pending on current visibility state.

Psuedo code:
sub Commandbutton1_Click:
----if layer1 is visible then:
--------layer1.visible = 0
----else
--------layer1.visible = 1
----end if
end sub
LVL 1
m_travisAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
A very similar question came up here once before and I still have the code that solved that problem. Please take a look and let me know if you need something different.
Determine-which-of-four-shapes-was-click
0
m_travisAuthor Commented:
what is the file type?
0
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
Very strange... it is a Visio diagram (.vsd) but it appears that the EE upload truncated the name -- including the file extension! Just rename the file and add .vsd to the  end and you should be all set.
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

m_travisAuthor Commented:
Here was my solution, some of the code was taken from Scott:
Private Sub CommandButton1_Click()
    If CommandButton1.Data1 = True Then
        'Turn Layer Off
        TurnLayerOff ("Inbound Mail")
        CommandButton1.Data1 = False
    Else
        'Turn Layer On
        TurnLayerOn ("Inbound Mail")
        CommandButton1.Data1 = True
    End If
End Sub

Private Sub CommandButton2_Click()
    If CommandButton2.Data1 = True Then
        'Turn Layer Off
        TurnLayerOff ("Outbound Mail")
        CommandButton2.Data1 = False
    Else
        'Turn Layer On
        TurnLayerOn ("Outbound Mail")
        CommandButton2.Data1 = True
    End If
End Sub

Private Sub CommandButton3_Click()
    If CommandButton3.Data1 = True Then
        'Turn Layer Off
        TurnLayerOff ("Retrieve Mail")
        CommandButton3.Data1 = False
    Else
        'Turn Layer On
        TurnLayerOn ("Retrieve Mail")
        CommandButton3.Data1 = True
    End If
End Sub

Private Sub CommandButton4_Click()
    If CommandButton4.Data1 = True Then
        'Turn Layer Off
        TurnLayerOff ("Replication")
        CommandButton4.Data1 = False
    Else
        'Turn Layer On
        TurnLayerOn ("Replication")
        CommandButton4.Data1 = True
    End If
End Sub

Function TurnLayerOff(x As String)
    Dim pg As Visio.Page
    Dim lyrTarget As Visio.Layer
    
    value = True
    Set pg = ActivePage
    Set lyrTarget = pg.Layers(x)
    lyrTarget.CellsC(visLayerVisible).Formula = 0
    
End Function

Function TurnLayerOn(x As String)
    Dim pg As Visio.Page
    Dim lyrTarget As Visio.Layer
    Dim value As Boolean
    
    value = True
    Set pg = ActivePage
    Set lyrTarget = pg.Layers(x)
    lyrTarget.CellsC(visLayerVisible).Formula = 1
    
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
m_travisAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for m_travis's comment #a40748526
Assisted answer: 300 points for scott's comment #a40747166

for the following reason:

My solution solved my problem. The other solution just contributed to the solution.
0
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
I'm glad my code provided some assistance, and thanks for posting your final code for the benefit of others.

Now I have a question: did you intend to close this question or accept your answer and mine? There is a difference at EE -- closing the question makes it go away, but accepting one or more answers leaves it here for others to learn from. If you intended the latter, use the "accept answers" links instead.

Thanks...
0
m_travisAuthor Commented:
I wanted to provide you credit for helping and accept your answer with mine to make the questioned answered. All i did was hit "Accept Multiple Solutions", select the answers, and submit. Is that the wrong process to follow?
0
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
No, that sounds correct, but for some reason the email I received said that you'd made a request to cancel the question.

Go ahead and try it again and I'll let it go either way. Thanks.
0
m_travisAuthor Commented:
My solution solved my problem. The other solution just contributed to the solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Visio

From novice to tech pro — start learning today.