Two Macros at the same time?? is it possible

0

0000_AAAA_0000

Hi, And Many Thanks in advance!

I would like to add a timing range and /or Shape, button to show for a
while "10 Seconds" the time going down
and while going down be able to press one other button, and run the
macro attached to it.
Is it Posibble??


My Try:
For X = 10 To 0 Step -1
Activesheet.Buttons("Time").Caption = X
'or Range("A1").Value=X
Application.Wait Now + TimeValue("00:00:01")
Next X


'so when I am showing this timing going down, be able to press a few
other macros.

Am I missing anything, is it possible??
Do I have to attach any doevents?? do loop??
Any Idea?

Thanks
 
F

Frank Stone

no. sorry to say. when one macro is running, it has
command of the CPU. no other actions or interrupt requests
can proceed untill the macro has stopped. You can throw in
a few doevents but that will only free the CPU to do
system events.
so running 2 macros at once is not possible.
as for a timer for the macro, unforumately there is no
timer control built in to excel. you can use the status
bar by adding application.statusbar = "yourmessage" in
your code at various stages to let you know about where
the macro is but that is about it. when done make sure you
set the status bar to nothing.
sorry.
Regards
Frank
 
J

Jake Marx

Hi,

Yes, you can do this (kind of). As Frank pointed out, you cannot run 2
separate VBA procedures at once. However, you could use Application.OnTime
to "run" your countdown timer. Between calls to the subroutine used in
OnTime (which would change the caption of your countdown button), your users
would be able to click other buttons to launch other macros. But the OnTime
procedure would not run again until the other code had finished with its
execution.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
R

Robin Hammond

OnTime might well fail if the other code is running at the the time that the
OnTime call is meant to be processed. It's clunky and has rarely worked
reliably for me, so I came up with an activex wrapper for the VB timer. You
can download this VBA timer from my site below.

As an illustration, I have just tested the following in Excel XP. Create a
form, with one command button, two labels, and add the VBA control to the
form. Set the timer properties to enabled and an interval of 1000, then run
the form. When first launched you'll see label1 updating with the time. When
you click the command button, you'll see the time continue to be updated
even while label2 shows the counter value.

Private Sub CommandButton1_Click()
Dim lCounter As Long
For lCounter = 1 To 10000000
Label2.Caption = lCounter
DoEvents
Next lCounter
End Sub

Private Sub Timer1_Timer()
Label1.Caption = "The time is: " & Time
End Sub

Robin Hammond
www.enhanceddatasystems.com


Jake Marx said:
Hi,

Yes, you can do this (kind of). As Frank pointed out, you cannot run 2
separate VBA procedures at once. However, you could use
Application.OnTime to "run" your countdown timer. Between calls to the
subroutine used in OnTime (which would change the caption of your
countdown button), your users would be able to click other buttons to
launch other macros. But the OnTime procedure would not run again until
the other code had finished with its execution.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


0000_AAAA_0000 said:
Hi, And Many Thanks in advance!

I would like to add a timing range and /or Shape, button to show for a
while "10 Seconds" the time going down
and while going down be able to press one other button, and run the
macro attached to it.
Is it Posibble??


My Try:
For X = 10 To 0 Step -1
Activesheet.Buttons("Time").Caption = X
'or Range("A1").Value=X
Application.Wait Now + TimeValue("00:00:01")
Next X


'so when I am showing this timing going down, be able to press a few
other macros.

Am I missing anything, is it possible??
Do I have to attach any doevents?? do loop??
Any Idea?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top