Automatically Run Macros Using Task Scheduler

mlarson

Well-known Member
Joined
Aug 25, 2011
Messages
509
Office Version
  1. 2010
Platform
  1. Windows
This is probably simple but I just don't know how to do it. What I do know is how to set up a task in Task Scheduler and I have it set to open my Excel file: Workbook1.xlsm. This task is set to run at 7am each morning. Workbook1.xlsm has a bunch of different macros in it.

What I'd like to do is to have each of those macros to run automatically when the file is automatically opened by Task Scheduler. How would I go about doing this?

Thanks for your help.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You could call the macros from the Workbook_Open event handler in the ThisWorkbook module in Workbook1.xlsm.
 
Upvote 0
John, apologies for my ignorance on this topic. Would these steps be correct?
1. Open Workbook1.xlsm
2. Go to Developer, then Visual Basic, then CTRL+R to bring up the project library
3. Under Workbook1.xlsm I see "Microsoft Excel Objects" and I should double-click on "ThisWorkBook"

What do I do after this step? I'm not sure what to include in the macro. Would it look something like the following?

Sub RunAllMacros()

Run Macro1
Run Macro2
Run Macro3

End Sub
 
Upvote 0
mlarson,

Double click on Thisworkbook. On the code window you have two dropdowns. On the left(it would be "General" by default) select Workbook. On the Right (it would be "Declarations" by default) select Open. When you select those tow you will get the code as shown below:
Code:
Private Sub Workbook_Open()

End Sub

Make sure you Call the Macros that you wanted to run in an sequential order as per your requirement.

Code:
Private Sub Workbook_Open()
Call Macro1
Call Macro2
Call Macro3
End Sub

-Abi
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,408
Members
452,912
Latest member
alicemil

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