View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
external usenet poster
 
Posts: 575
Default Two Macros at the same time?? is it possible

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" wrote in message
...
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 wrote:
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