How to set a Excel macro to run during set time?

ld1414

New Member
Joined
Mar 5, 2018
Messages
17
Morning all,

Looking for assistance on setting up a Macro to update at a set time every evening. Currently our team has excel sets that perform data pulls every morning using a macro called "Update". I was wondering if I can enter a code into this Macro to run at 3am daily? Can anyone advise how this is done? Do I enter the code and leave the workbook open each night, then come in the morning to a updated version?

Thanks for your help.
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Here is one way I have done it:

1. Create a version of the Excel workbook that has a "Workbook_Open" event procedure, which is VBA code that runs automatically upon opening the Excel file.
2. In the "Workbook_Open" event procedure, have it call/run the macro you want to run, and then close the workbook when finished.
3. Use a Scheduler (like "Windows Scheduler") to open this Excel file on the appointed days/times.
This will have to be on a computer that will always be turned on on those days/times. I typically use a Server.

As long as you make sure that Macros are enabled when opened from that computer (server), the code should run and close itself.

There are also ways to use Command Line to open the Excel file and run a particular macro from Windows Scheduler (then you don't need to use "Workbook_Open" or have a separate copy of the file).
 
Last edited:
Upvote 0
Joe's method is probably safer, but you can also use the OnTime method. Leave your workbook open when you leave, run a 1-line macro with the OnTime instruction before you leave for the day, and it should run the macro when desired.

https://docs.microsoft.com/en-us/office/vba/api/excel.application.ontime


Hi Eric,

So I believe your method is easier for me to use (though I know probably more inefficient). I seem to be having some trouble kicking this off with the code below. Time passes and nothing starts. Am I labeling the "encumbrance marco" correctly?





Private Sub Workbook_Open()


Application.OnTime TimeValue("10:49:15"), "Encumbrance_Macro"


End Sub




Sub Encumbrance()
'
' Encumbrance Macro
 
Upvote 0
This was perfect and it's now running. Thank you. I suppose last question for everyone is if the computer is locked, but profile and excel sheet still open. I imagine this will still run overnight correct? Thank you all again. This will save our team tons of time.
 
Upvote 0
It should, although that sounds easy enough to test. You may want to actually check the first time it runs. Glad we could help.
 
Upvote 0
Another thought - you should also make sure that the sleep settings on your PC don't make the PC go to sleep before you want it to.
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,989
Members
452,541
Latest member
haasro02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top