Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Don't re-run macro for five seconds...?

Hi newsgroup,

I have a macro that runs some code when a tab is clicked on. Now the
problem is that this macro changes tabs and does some other stuff
there and then returns to the initial tab. Which would trigger the
same macro again.

To prevent this I would ideally have a timer in the macro to prevent
it from looping in that it should not do the same macro twice within 5
seconds (or something along those lines).

Is this possible? And if so, how? :)

Many thanks,

Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 621
Default Don't re-run macro for five seconds...?

I assume worksheet_activate event taking place.

Post the code.

Very rarely you would need to switch tabs to do some other stuff.

You may also disable events to prevent the looping.

On Error GoTo wsexit
Application.EnableEvents = False
switch sheets
do some other stuff
return to original sheet
wsexit:
Application.EnableEvents = True


Gord




On Tue, 29 Nov 2011 06:32:33 -0800 (PST), Chris J Denver
wrote:

Hi newsgroup,

I have a macro that runs some code when a tab is clicked on. Now the
problem is that this macro changes tabs and does some other stuff
there and then returns to the initial tab. Which would trigger the
same macro again.

To prevent this I would ideally have a timer in the macro to prevent
it from looping in that it should not do the same macro twice within 5
seconds (or something along those lines).

Is this possible? And if so, how? :)

Many thanks,

Chris

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Don't re-run macro for five seconds...?

Hi Gord,

Yes this is triggered by Worksheet_Activate

what it then does is call a number of other macros on some other
sheets, and some of them require the tabs to be changed:

Sub Worksheet_Activate()

Application.ScreenUpdating = False
Call Sheet17.macrosort
Call Sheet35.macrofill
Call Sheet64.macrosort
ActiveWorkbook.Worksheets("Printsheet").Select
Range("A1").Select
Application.ScreenUpdating = True

Now i guess i could rewrite all those macros in a way that you
actually don't need to be on the respective tabs, but this would be
quite cumbersome...

I will give the disable events thing a go, thanks for that.

Best,

Chris


On Nov 29, 4:30*pm, Gord Dibben wrote:
I assume worksheet_activate event taking place.

Post the code.

Very rarely you would need to switch tabs to do some other stuff.

You may also disable events to prevent the looping.

On Error GoTo wsexit
Application.EnableEvents = False
* * * *switch sheets
* * * * * *do some other stuff
* * * *return to original sheet
wsexit:
Application.EnableEvents = True

Gord

On Tue, 29 Nov 2011 06:32:33 -0800 (PST), Chris J Denver

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Don't re-run macro for five seconds...?

Chris J Denver formulated on Tuesday :
Now i guess i could rewrite all those macros in a way that you
actually don't need to be on the respective tabs, but this would be
quite cumbersome...


It's worth the effort because, as Gord states, rarely is it necessary
to make sheets active to work on them, AND it's more efficient to write
code that reduces ALL unnecessary action whether behind the scenes or
not.

If what you mean by "cumbersome" is changing all refs to 'ActiveSheet'
in your code, use Find/Replace (Ctrl+H) and change each sheet module to
refer to itself instead of ActiveSheet (as was rendered by the macro
recorder). That means replace "ActiveSheet" with "Me", and add dots
where needed so your code implements 'fully qualified references'. This
is just 'good programming practice' <IMO and so is worth
learning/adopting as an inherent programming skill anytime you write
code.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Don't re-run macro for five seconds...?

Hi Garry,

thanks for this feedback, it's not mainly the ActiveSheet, it's more
selection. Lots of sorts and changes I've got in the macros run on the
selections, so for those I would need an indirect address. Also I
dynamically give charts data, for which I use the
ActiveChart.SetSourceData functions. Again I guess there's a way to
address charts differently?

Best,

Chris

On Nov 29, 4:59*pm, GS wrote:
Chris J Denver formulated on Tuesday :

Now i guess i could rewrite all those macros in a way that you
actually don't need to be on the respective tabs, but this would be
quite cumbersome...


It's worth the effort because, as Gord states, rarely is it necessary
to make sheets active to work on them, AND it's more efficient to write
code that reduces ALL unnecessary action whether behind the scenes or
not.

If what you mean by "cumbersome" is changing all refs to 'ActiveSheet'
in your code, use Find/Replace (Ctrl+H) and change each sheet module to
refer to itself instead of ActiveSheet (as was rendered by the macro
recorder). That means replace "ActiveSheet" with "Me", and add dots
where needed so your code implements 'fully qualified references'. This
is just 'good programming practice' <IMO and so is worth
learning/adopting as an inherent programming skill anytime you write
code.

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Don't re-run macro for five seconds...?

Chris J Denver formulated on Tuesday :
thanks for this feedback, it's not mainly the ActiveSheet, it's more
selection. Lots of sorts and changes I've got in the macros run on the
selections, so for those I would need an indirect address. Also I
dynamically give charts data, for which I use the
ActiveChart.SetSourceData functions. Again I guess there's a way to
address charts differently?


Sounds, then, like Gord's suggestion is the better way to go!<IMO

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 621
Default Don't re-run macro for five seconds...?

I will give the disable events thing a go, thanks for that.

Let us know how you make out.


Gord

On Tue, 29 Nov 2011 08:43:08 -0800 (PST), Chris J Denver
wrote:

Hi Gord,

Yes this is triggered by Worksheet_Activate

what it then does is call a number of other macros on some other
sheets, and some of them require the tabs to be changed:

Sub Worksheet_Activate()

Application.ScreenUpdating = False
Call Sheet17.macrosort
Call Sheet35.macrofill
Call Sheet64.macrosort
ActiveWorkbook.Worksheets("Printsheet").Select
Range("A1").Select
Application.ScreenUpdating = True

Now i guess i could rewrite all those macros in a way that you
actually don't need to be on the respective tabs, but this would be
quite cumbersome...

I will give the disable events thing a go, thanks for that.

Best,

Chris


On Nov 29, 4:30*pm, Gord Dibben wrote:
I assume worksheet_activate event taking place.

Post the code.

Very rarely you would need to switch tabs to do some other stuff.

You may also disable events to prevent the looping.

On Error GoTo wsexit
Application.EnableEvents = False
* * * *switch sheets
* * * * * *do some other stuff
* * * *return to original sheet
wsexit:
Application.EnableEvents = True

Gord

On Tue, 29 Nov 2011 06:32:33 -0800 (PST), Chris J Denver

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Don't re-run macro for five seconds...?

Gord,

the disable events works great and I also understand how it works
(which is a plus), many thanks for this.

Chris

On Nov 29, 5:06*pm, Gord Dibben wrote:
I will give the disable events thing a go, thanks for that.


Let us know how you make out.

Gord

On Tue, 29 Nov 2011 08:43:08 -0800 (PST), Chris J Denver







wrote:
Hi Gord,


Yes this is triggered by Worksheet_Activate


what it then does is call a number of other macros on some other
sheets, and some of them require the tabs to be changed:


Sub Worksheet_Activate()


* *Application.ScreenUpdating = False
* *Call Sheet17.macrosort
* *Call Sheet35.macrofill
* *Call Sheet64.macrosort
* *ActiveWorkbook.Worksheets("Printsheet").Select
* *Range("A1").Select
* *Application.ScreenUpdating = True


Now i guess i could rewrite all those macros in a way that you
actually don't need to be on the respective tabs, but this would be
quite cumbersome...


I will give the disable events thing a go, thanks for that.


Best,


Chris


On Nov 29, 4:30 pm, Gord Dibben wrote:
I assume worksheet_activate event taking place.


Post the code.


Very rarely you would need to switch tabs to do some other stuff.


You may also disable events to prevent the looping.


On Error GoTo wsexit
Application.EnableEvents = False
switch sheets
do some other stuff
return to original sheet
wsexit:
Application.EnableEvents = True


Gord


On Tue, 29 Nov 2011 06:32:33 -0800 (PST), Chris J Denver


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 621
Default Don't re-run macro for five seconds...?

Thanks for the feedback.


Gord

On Tue, 29 Nov 2011 09:25:56 -0800 (PST), Chris J Denver
wrote:

Gord,

the disable events works great and I also understand how it works
(which is a plus), many thanks for this.

Chris

On Nov 29, 5:06*pm, Gord Dibben wrote:
I will give the disable events thing a go, thanks for that.


Let us know how you make out.

Gord

On Tue, 29 Nov 2011 08:43:08 -0800 (PST), Chris J Denver







wrote:
Hi Gord,


Yes this is triggered by Worksheet_Activate


what it then does is call a number of other macros on some other
sheets, and some of them require the tabs to be changed:


Sub Worksheet_Activate()


* *Application.ScreenUpdating = False
* *Call Sheet17.macrosort
* *Call Sheet35.macrofill
* *Call Sheet64.macrosort
* *ActiveWorkbook.Worksheets("Printsheet").Select
* *Range("A1").Select
* *Application.ScreenUpdating = True


Now i guess i could rewrite all those macros in a way that you
actually don't need to be on the respective tabs, but this would be
quite cumbersome...


I will give the disable events thing a go, thanks for that.


Best,


Chris


On Nov 29, 4:30 pm, Gord Dibben wrote:
I assume worksheet_activate event taking place.


Post the code.


Very rarely you would need to switch tabs to do some other stuff.


You may also disable events to prevent the looping.


On Error GoTo wsexit
Application.EnableEvents = False
switch sheets
do some other stuff
return to original sheet
wsexit:
Application.EnableEvents = True


Gord


On Tue, 29 Nov 2011 06:32:33 -0800 (PST), Chris J Denver

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
How do I change a minutes and seconds as a 2400 time to seconds? NickBrown419 Excel Worksheet Functions 1 August 10th 08 09:12 PM
Formula to Change Hours:Minutes:Seconds to Seconds only Cheri Excel Discussion (Misc queries) 4 August 30th 06 12:44 AM
Converting Julian Seconds with a macro to replace old seconds data Keldair Excel Discussion (Misc queries) 2 February 18th 06 12:09 AM
Convert "Time Interval" in "hours : minutes : seconds" to seconds Ianukotnorth New Users to Excel 7 May 8th 05 08:11 PM
Convert seconds to minutes and seconds in excel anonymous Excel Worksheet Functions 3 December 25th 04 08:38 PM


All times are GMT +1. The time now is 07:20 PM.

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

About Us

"It's about Microsoft Excel"