Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
Hi all, If these work, to call macro's: Sub RunCode1() Code1 End Sub Sub RunCode2() Code2 End Sub Why dosen't this work, to toggle the calls? Sub testoftoggle() If Code1 = True Then Code2 Else Code1 End If End Sub -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
Hi Dave,
I am not sure that I understand, but perhaps: Sub RunCode1() MsgBox "Code1" End Sub Sub RunCode2() MsgBox "Code2" End Sub Sub testoftoggle() If Date #1/3/2006# = True Then RunCode2 Else RunCode1 End If End Sub --- Regards, Norman "Desert Piranha" <Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in message news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com... Hi all, If these work, to call macro's: Sub RunCode1() Code1 End Sub Sub RunCode2() Code2 End Sub Why dosen't this work, to toggle the calls? Sub testoftoggle() If Code1 = True Then Code2 Else Code1 End If End Sub -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
Because a sub can't return a value, so it can't have a value of True.
If it was a function and could, then you would have to run it to get that value. -- Regards, Tom Ogilvy "Desert Piranha" <Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in message news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com... Hi all, If these work, to call macro's: Sub RunCode1() Code1 End Sub Sub RunCode2() Code2 End Sub Why dosen't this work, to toggle the calls? Sub testoftoggle() If Code1 = True Then Code2 Else Code1 End If End Sub -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
Hi Norman, What i am trying to do is have one call, If i call it once it will call Code1, If i call it again it will call Code2, If i call again it will call code1, as in a toggle. But i don't have the code in there, They are just a call to code elsewhere. Yours would be what i am trying, without the date stuff. Sub testoftoggle() If Date #1/3/2006# = True Then RunCode2 Else RunCode1 End If End Sub Norman Jones Wrote: Hi Dave, I am not sure that I understand, but perhaps: Sub RunCode1() MsgBox "Code1" End Sub Sub RunCode2() MsgBox "Code2" End Sub Sub testoftoggle() If Date #1/3/2006# = True Then RunCode2 Else RunCode1 End If End Sub --- Regards, Norman "Desert Piranha" <Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in message news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com... Hi all, If these work, to call macro's: Sub RunCode1() Code1 End Sub Sub RunCode2() Code2 End Sub Why dosen't this work, to toggle the calls? Sub testoftoggle() If Code1 = True Then Code2 Else Code1 End If End Sub -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
Hi Tom, Thx for the input, I will look at a function. Dave Tom Ogilvy Wrote: Because a sub can't return a value, so it can't have a value of True. If it was a function and could, then you would have to run it to get that value. -- Regards, Tom Ogilvy "Desert Piranha" <Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in message news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com... Hi all, If these work, to call macro's: Sub RunCode1() Code1 End Sub Sub RunCode2() Code2 End Sub Why dosen't this work, to toggle the calls? Sub testoftoggle() If Code1 = True Then Code2 Else Code1 End If End Sub -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
Hi Dave,]
At the top of the code module, before any code, insert: Public myToggle As Boolean Then try: Sub RunCode1() MsgBox "Code1" End Sub Sub RunCode2() MsgBox "Code2" End Sub Sub testoftoggle() If myToggle Then RunCode2 Else RunCode1 End If myToggle = Not myToggle End Sub --- Regards, Norman |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
Hi Dave,
Instead of using a public variable, you could also try: Sub RunCode1() MsgBox "Code1" End Sub Sub RunCode2() MsgBox "Code2" End Sub Sub testoftoggle() Static myToggle As Boolean If myToggle Then RunCode2 Else RunCode1 End If myToggle = Not myToggle End Sub --- Regards, Norman |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
No, don't.
-- Regards, Tom Ogilvy "Desert Piranha" <Desert.Piranha.23yxqn_1141179004.7216@excelforu m-nospam.com wrote in message news:Desert.Piranha.23yxqn_1141179004.7216@excelfo rum-nospam.com... Hi Tom, Thx for the input, I will look at a function. Dave Tom Ogilvy Wrote: Because a sub can't return a value, so it can't have a value of True. If it was a function and could, then you would have to run it to get that value. -- Regards, Tom Ogilvy "Desert Piranha" <Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in message news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com... Hi all, If these work, to call macro's: Sub RunCode1() Code1 End Sub Sub RunCode2() Code2 End Sub Why dosen't this work, to toggle the calls? Sub testoftoggle() If Code1 = True Then Code2 Else Code1 End If End Sub -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
Hi Tom, No ,Don't <-- What? use a public variable? Dave Tom Ogilvy Wrote: No, don't. -- Regards, Tom Ogilvy "Desert Piranha" <Desert.Piranha.23yxqn_1141179004.7216@excelforu m-nospam.com wrote in message news:Desert.Piranha.23yxqn_1141179004.7216@excelfo rum-nospam.com... Hi Tom, Thx for the input, I will look at a function. Dave Tom Ogilvy Wrote: Because a sub can't return a value, so it can't have a value of True. If it was a function and could, then you would have to run it to get that value. -- Regards, Tom Ogilvy "Desert Piranha" <Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in message news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com... Hi all, If these work, to call macro's: Sub RunCode1() Code1 End Sub Sub RunCode2() Code2 End Sub Why dosen't this work, to toggle the calls? Sub testoftoggle() If Code1 = True Then Code2 Else Code1 End If End Sub -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 -- Desert Piranha ------------------------------------------------------------------------ Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934 View this thread: http://www.excelforum.com/showthread...hreadid=517572 |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
Hi Norman, Both of your examples work great. Thank you very much. I couldn't figure that one out. Dave Norman Jones Wrote: Hi Dave, Instead of using a public variable, you could also try: Sub RunCode1() MsgBox "Code1" End Sub Sub RunCode2() MsgBox "Code2" End Sub Sub testoftoggle() Static myToggle As Boolean If myToggle Then RunCode2 Else RunCode1 End If myToggle = Not myToggle End Sub --- Regards, Norma -- Desert Piranh ----------------------------------------------------------------------- Desert Piranha's Profile: http://www.excelforum.com/member.php...fo&userid=2893 View this thread: http://www.excelforum.com/showthread.php?threadid=51757 |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Code Calls
Thx for the input, I will look at a function.
Too bad the Excel Forum isn't linear. It makes more sense in a Usenet reader. -- Regards, Tom Ogilvy |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Command button to toggle worksheet event code on / off? | Excel Discussion (Misc queries) | |||
Toggle Code | Excel Programming | |||
toggle button & event code | Excel Programming | |||
Can I toggle this Code - to Stamp and to UnStamp? | Excel Programming | |||
XLA calls dll | Excel Programming |