View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
Harlan Grove Harlan Grove is offline
external usenet poster
 
Posts: 733
Default How do I prevent AutoRun Macros when Programmatically Opening Workbook?

Joseph Geretz wrote...
I have an application which uses Word and Excel as automation servers. When
opening a document, I need to prevent macros from running automatically.

....

In Excel only two types of macros would run when opening a workbook
interactively - event handlers (not just Workbook_Open, but also
Calculate and SheetCalculate if there are any volatile functions called
in applicable cells) and the legacy Auto_Open macros. If you open a
workbook using VBA, Excel *won't* run its Auto_Open macros, but if
events are enabled, it will run event handlers in the opened workbook.
So disable event handlers prior to opening workbooks and enable them
afterwards.

On Error Resume Next
Application.EnableEvents = False
Workbooks.Open . . .
Application.EnableEvents = True
On Error Goto 0