Macro With Timer Event
On 9 Dec 2005 07:14:45 -0800, Dave O wrote:
VBA has a function called Timer, a long-type integer that represents
the current number of seconds since midnight. You can use this in code
to create a delay of a number of seconds like this:
Sub Delay()
Dim Beg As Long
Beg = Timer
Do
Loop Until Timer - Beg = 30
End Sub
This assigns the variable Beg (for Begin) with the current Timer value.
Then a DO loop starts that does nothing but loop until 30 seconds
elapses.
Does that do it for you?
Below is the code which gives me a compile error on the 2nd Sub Delay().
It is a simple copy from sheet 1 to sheets 2,3,4 and 5. Can you see
anything wrong. Help much appreciated.
Thanks.
.................................................. ....................
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/12/2005 by John
'
' Keyboard Shortcut: Ctrl+m
'
Range("A1:A5").Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
End Sub
Sub Delay()
Dim Beg As Long
Beg = Timer
Do
Loop Until Timer - Beg = 30
Sheets("Sheet1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet3").Select
ActiveSheet.Paste
End Sub
Sub Delay()
Dim Beg As Long
Beg = Timer
Do
Loop Until Timer - Beg = 30
Sheets("Sheet1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet4").Select
ActiveSheet.Paste
End Sub
Sub Delay()
Dim Beg As Long
Beg = Timer
Do
Loop Until Timer - Beg = 30
Sheets("Sheet1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet5").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
End Sub
|