Run macro with Windows Task Scheduler

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
Currently I have a task setup which opens my workbook every day at a set time, runs 2 macros in the workbook open procedure and then closes excel.

However as the macros email people, having the code run on the workbook open procedure is not ideal. If the file is opened at any other time these emails will still be sent, which will just confuse people (it also makes it a pain to edit as the procedure closes the workbook.)

Is there a way to use the task scheduler to run specific Macros so I wouldn't have to have them in the workbook open procedure?
 
Last edited:
Running Excel 2007, OS = Vista
Create a .vbs file and run from Task Manager

Code:
Dim oExcel
Set oExcel = WScript.CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.Workbooks.Open "C:\MyPath\MyProgram.xlsm"
oExcel.Run "'MyProgram.xlsm'!Main"
oExcel.workbooks("MyProgram.xlsm").Close False
oExcel.Quit
Set oExcel = Nothing
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,224,802
Messages
6,181,054
Members
453,014
Latest member
Chris258

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