Schedule a VBA Macro (ALARM Setting)

Heylo, How is your office life going on? I pray for all of you and wish you lots of wealth and a very good health. Coming to our topic, we're actually gonna discuss Application.OnTime Object of Application class.
For details: Please visit Microsoft MSDN here:
http://msdn.microsoft.com/en-us/library/aa195809(office.11).aspx

We used Now + TimeValue(time) in our example to schedule something to be run when a specific amount of time (counting from now) has elapsed as TimeValue(time) is used to schedule something to be run a specific time.

For e.g.
1. This example runs my_Procedure 15 seconds from now.
Application.OnTime Now + TimeValue("00:00:15"), "my_Procedure"

2. This example runs my_Procedure at 5 P.M.
Application.OnTime TimeValue("17:00:00"), "my_Procedure"


Sample Code:
Option Explicit


Sub ScheduleAMacro()
Application.OnTime Now + TimeSerial(0, 1, 0), "AlarmMacro"
End Sub

'This should be the macro that runs after one minute
'We simply pops up a message box.
Sub AlarmMacro()
MsgBox "The code was just executed!"
End Sub



Comments

Anonymous said…
Hi..Do we need to left excel open till to run or schdule a macro to run or it can run by itself...
Anonymous said…
excel must be running.

VBA code is compiled during excel work
Jock Rocket 3 said…
Does this run if Excel is running but this particular file is not open. Also can you scehdule by date instead of time, maybe even by date and time?

Many thanks
MITHUN said…
i am getting an error that the macro AlarmMacro() cannot be run....

The réason it says is that "the macro may not be available in this workbbok or all macros may be disabled".....

But the macro is in the same workbook and all macros are enabled.
MITHUN said…
I am getting an error when i run this code. macro AlarmMacro() does not run.

it says "the macro may not be available in this workbook or all macros may be disabled"

but the macro is in the same workbook and all macros are enabled.
MITHUN said…
I am getting an error when i run this code. macro AlarmMacro() does not run.

it says "the macro may not be available in this workbook or all macros may be disabled"

but the macro is in the same workbook and all macros are enabled.