How do I prevent AutoRun Macros when Programmatically Opening Workbook?
I'm confused.
No, maybe I'm confused; but if so it's for good reason. Seemingly, the
development analysts at Redmond made some sort of decision to engineer Excel
differently than Word in this respect? Or maybe no analysis was performed at
all, in which case it was left up to the individual development groups which
explains the statistically expected results (two tosses of the coin).
1. Word runs AutoRun macros automatically when a document is opened via
automation
2. Excel doesn't (?)
I had observed symptom #1 as described in Word and assumed that it
would be the same in Excel. But if it's not, then the problem I had with
Word documents doesn't present itself with Excel documents and so there's
nothing I need to do.
Please confirm, whether or not this is in fact the case.
Thanks!
- Joseph Geretz -
"Peter T" <peter_t@discussions wrote in message
...
Oops, thought I was replying to a response from Joseph (OP) hence I was
confused, whereas of course I replied to a post from Jezebel who I think
has
misread the OP.
Regards,
Peter T
"Peter T" <peter_t@discussions wrote in message
...
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
|