Batch file to open and run two macros in excel

ctbanker

New Member
Joined
Aug 26, 2015
Messages
26
Hi All,

I want to create a batch file to open and run two different macros in excel. The reason I need a batch file is to do this automatically for me without me having to manually open the excel file. For some reason, when I use Task Scheduler to open my excel file (with macros), it simply opens the file but doesn't run the macro. Help would be greatly appreciated!!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Not a batch file, but a script. Save the file with the extension ".vbs".

Code:
Option Explicit

Dim xlApp, xlBook

Set xlApp = CreateObject("Excel.Application")
xlApp.visible=true
Set xlBook = xlApp.Workbooks.Open("~your_path_here\~your_workbook_here.xlsm", 0, True)
xlApp.Run "~your_macro_here"
xlBook.Close
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing
 
Upvote 0
And if you want to run two macros, simply add the following (under "xlApp.Run "~your_macro_here"):

xlApp.Run "~second macro name here~"

Sorry, I'm very new to vba, vbs, etc. Thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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