Discussion:
Macro Toggle On/Off
(too old to reply)
Chipmunk
2006-05-15 18:50:01 UTC
Permalink
Hello, how can I execute two different macros from a single toggle button?

Example: I press the toggle button and macro1 executes,
I press the same button again and macro2 executes,
I press the same button again and macro1 executes etc...

Thanks
Norman Jones
2006-05-15 19:03:03 UTC
Permalink
Hi Chipmunk,

Try something like:

'=============>>
Public Sub ToggleIt()
Static blFlag As Boolean

blFlag = Not blFlag

If blFlag Then
'Action 1 e.g.:
MsgBox "Action1"
Else
'Action 2 , e.g.:
MsgBox "Action 2"
End If

End Sub
'<<=============


---
Regards,
Norman
Post by Chipmunk
Hello, how can I execute two different macros from a single toggle button?
Example: I press the toggle button and macro1 executes,
I press the same button again and macro2 executes,
I press the same button again and macro1 executes etc...
Thanks
Norman Jones
2006-05-15 19:14:49 UTC
Permalink
Hi Chipmunk,

Just to add, the demo actions may be calls to discrete macros. So, for
Post by Norman Jones
MsgBox "Action1"
might be replaced with the instruction:

Call Macro1

---
Regards,
Norman
Chipmunk
2006-05-15 19:21:02 UTC
Permalink
Thanks, that did it. Well I changed MsgBox to Call. Thanks again.
Post by Norman Jones
Hi Chipmunk,
'=============>>
Public Sub ToggleIt()
Static blFlag As Boolean
blFlag = Not blFlag
If blFlag Then
MsgBox "Action1"
Else
MsgBox "Action 2"
End If
End Sub
'<<=============
---
Regards,
Norman
Post by Chipmunk
Hello, how can I execute two different macros from a single toggle button?
Example: I press the toggle button and macro1 executes,
I press the same button again and macro2 executes,
I press the same button again and macro1 executes etc...
Thanks
Ikaabod
2006-05-15 19:14:10 UTC
Permalink
Private Sub ToggleButton1_Click()
If ToggleButton1 = True Then
'Call YourMacro1
Exit Sub
Else
'Call YourMacro2
Exit Sub
End If
End Sub
Post by Chipmunk
Hello, how can I execute two different macros from a single toggl
button?
Example: I press the toggle button and macro1 executes,
I press the same button again and macro2 executes,
I press the same button again and macro1 executes etc...
Thank
--
Ikaabo
-----------------------------------------------------------------------
Ikaabod's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3337
View this thread: http://www.excelforum.com/showthread.php?threadid=54223
Loading...