There are a few fairly simple bits of code you can use to delay Excel VBA code from running, or choose for it to run only on particular days or particular times. Maybe you are kicking off the Excel macro as a Scheduled Task, or maybe it runs when a button is clicked. If someone clicks the button during office hours, for example, you may not want it to execute the macro.
Here are some scenarios and examples of how to use VBA in each case. I’ll be unimaginative and use Macro1 as the name for all the procedures in the examples, but obviously that will need replacing with your macro name.
The first routine will run Macro1 if kicked off before 9am (always remember to use a 24 hour clock) and the second routine kicks it off on a Monday. Note that by default weekday 1 is Sunday, 2 Mon, 3 Tue, etc.
If you wanted to kick off the macro at exactly 2pm, you can simply add this line of code.
Application.OnTime TimeValue(“14:00:00”), “Macro1”