Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command button to toggle worksheet event code on / off? Fred[_2_] Excel Discussion (Misc queries) 15 July 31st 07 11:50 AM
Toggle Code thunderfoot[_2_] Excel Programming 2 September 26th 05 06:26 PM
toggle button & event code Bob Umlas[_3_] Excel Programming 0 April 14th 05 08:22 PM
Can I toggle this Code - to Stamp and to UnStamp? JMay Excel Programming 1 January 9th 04 12:47 PM
XLA calls dll rodt Excel Programming 2 November 17th 03 10:08 PM


All times are GMT +1. The time now is 03:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"