user1199080
user1199080

Reputation: 201

Set a windows task scheduler to open excel and execute an excel macro after 5 minutes

I need to run an excel macro at 3.00am in the morning. I can set up the task scheduler to be open up excel at 2.55am. However, how do i get excel to execute the macro only after 5 minutes, that it has opened?

Upvotes: 0

Views: 4071

Answers (2)

JMax
JMax

Reputation: 26591

As Nishant pointed out, you should use the Workbook_Open procedure to trigger a macro when the workbook opens.

The best way is to open you workbook at 3:00am and Workbook_Open will trigger the macro.

Yet, if you really need to wait, you'd better use Application OnTime like this:

Sub RunOnTime()
    dTime = Now + TimeSerial(0, 0, 10)
    Application.OnTime dTime, "RunMe"
End Sub

Upvotes: 0

Nishant Sharma
Nishant Sharma

Reputation: 360

You could launch the excel at 3 a.m. and trigger your macro from the WORKBOOK_OPEN event by adding a

Private Sub Workbook_Open()
   RunUrMacro()
End Sub

To your workbook.

If you absolutely need to load at 2.55 and run at 3 then you could sleep the application for 5 minutes using Application.Wait

Upvotes: 1

Related Questions