Home » excel » vba – how to use VBS run Excel Macro, but not run the Workbook_Open()

vba – how to use VBS run Excel Macro, but not run the Workbook_Open()

Posted by: admin May 14, 2020 Leave a comment

Questions:

Need your help.
I want to use vbs file to run excel macro, in the xlsm file there is Workbook_Open(), I don’t want to run it, I want to run some other macro, eg, Module1.test1111

But when I open open the excel file in vbs, or run other macro directly by using below code, the Workbook_Open() will run automatically.

Please give some advice how to avoid Workbook_Open() run, thanks.

Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Visible = true
objExcel.Application.Run "'test1.xlsm'!Module1.test1111"
How to&Answers:

You do not need to specify the Application. objExcel is the Application. And to disable the Workbook_Open(), switch off the events

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = true
objExcel.EnableEvents = False
objExcel.Run "'C:\Users\routs\Desktop\Sample.xlsm'!Module1.test1111"

Also remember to switch them back on 😉