简体   繁体   中英

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

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"

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 ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM