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

I'm confused. You specifically asked about opening an Excel Workbook and
preventing it's open events from running. I tried to clarify that when using
automation they do not automatically fire. Excel does not have an equivalent
of Word's Normal.dot.

In addition other workbooks that normally auto load on Excel startup, such
as "checked" addins and files in the StartupPath (typically xlstart folder),
do not open when starting an instance of Excel with automation.

Regards,
Peter T

"Jezebel" wrote in message
...
I don't know about Excel, but Word ones do. Try it: add an AutoOpen macro

to
word's normal.dot, then, from Excel, open a Word document ...


"Peter T" <peter_t@discussions wrote in message
...
Hi Joseph,

I might be missing something in your question but with automation the

auto
open/close events do not run unless you explicitly make them. In other
words
nothing to do to prevent them running automatically. Put open/close

events
in a saved book and try following with / without RunAutoMacros.

Dim oXL As Object ' Excel.Application
Dim oWB As Object ' Excel.Workbook

Sub TestOpen()
Dim s As String
s = "C:\Temp\Book2.xls"
'Set oXL = New Excel.Application 'early binding with As

excel.Application
Set oXL = CreateObject("Excel.application")

Set oWB = oXL.Workbooks.Open(s)
oXL.Visible = True

oWB.RunAutoMacros xlAutoOpen

End Sub
Sub TestClose()

oWB.RunAutoMacros xlAutoClose
oWB.Close
Set oWB = Nothing

oXL.Quit
Set oXL = Nothing

End Sub

Regards,
Peter T

"Joseph Geretz" wrote in message
...
I have an application which uses Word and Excel as automation servers.

When
opening a document, I need to prevent macros from running

automatically.

For Word documents I can do this as follows:

m_AppWord.WordBasic.DisableAutoMacros 1
Set m_DocWord = m_AppWord.Documents.Open(CStr(m_Document), False,

True,
False)

What is the equivalent statement for Excel which I should be coding

directly
before opening the file?

Set m_DocExcel = m_AppExcel.Workbooks.Open(CStr(m_Document))

Thanks for your help!

- Joseph Geretz