Toggle Code not Working (VBA)

nomido14

New Member
Joined
Oct 8, 2014
Messages
2
Hi all,

I have the following code which is looking to use a Toggle Button to show / hide a Layer in Visio (I know this is an Excel forum but hopefully the VBA skills are transferable and you can help)...

The button seems to hide the Layer but when clicked again the layer does not re-appear. Does anyone know why?

Thanks.

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

End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
What are you trying to do here?
Code:
If CommandButton1.Value Then
    LayerCellObj.Formula = True Or 1
Else
    LayerCellObj.Formula = False Or 0
End If

Shouldn't True or 1 be 1/"1" and False Or 0 be 0/"0"?

Is it actually a toggle button or a command button?

Have you checked what value it is actually returning when clicked/toggled?
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top