Excel Script to run macros inside excel

Hello Experts...

I have excel spreadsheet that has 3 macros. I have done some research and I want to use a script to call these 3 macros in order.

So I want the script to open excel, run the macros and then close..

Any ideas?
Nick CollinsAsked:
Who is Participating?
NorieVBA ExpertCommented:

Give this a try.
Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = True ' optional

Set xlWB = xlApp.Workbooks.Open("C:\Test\NameOfWorkbookWithMacros.xlsm")

xlApp.Run "'" & xlWB.Name & "'!NameOfMacro1"

xlApp.Run "'" & xlWB.Name & "'!NameOfMacro2"

xlApp.Run "'" & xlWB.Name & "'!NameOfMacro3"

xlWB.Close True


Open in new window

NorieVBA ExpertCommented:

Do you mean do all this in VBScript, or similar?

Or do you want to open this workbook from another workbook and run all 3 macros using VBA?
Nick CollinsAuthor Commented:
Yes all in a VBS script
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
What about this?
Dim xlApp,wb

Set xlApp = CreateObject("Excel.Application")
Set wb = xlApp.Workbooks.Open("C:\Users\sktneer\Desktop\MyExcelFile.xlsm")

wb.Application.Run "Macro1"
wb.Application.Run "Macro2"
wb.Application.Run "Macro3"

wb.Close False

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.