Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
use Private Sub Auto_Open in a general module instead of Private Sub
Workbook_Open() in thisworkbook. -- Gary "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 |
#3
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
Hi Gary,
I'm not sure what you are proposing. I don't have access to the internals of the documents which I am opening. My code which I presented is from my document handling application which is on the 'outside' of the documents. I'm simply opening these document by using server instances of Word and Excel via automation. I'm looking for a way to programmatically open these documents, while at the same time circumventing any AutoRun (or AutoExecute) macros which may be encoded into the documents. Thanks, - Joseph Geretz "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... use Private Sub Auto_Open in a general module instead of Private Sub Workbook_Open() in thisworkbook. -- Gary "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 |
#4
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
Set the AutomationSecurity property to msoAutomationSecurityForceDisable
before opening the file. Remember to set it back when you've finished. Use a sequence something like -- Dim pWord As Word.Application Dim pDoc As Word.Document Dim pSetting As MsoAutomationSecurity Set pWord = New Word.Application pSetting = pWord.AutomationSecurity pWord.AutomationSecurity = msoAutomationSecurityForceDisable Set pDoc = pWord.Documents.Open([FileName]) pWord.AutomationSecurity = pSetting "Joseph Geretz" wrote in message ... Hi Gary, I'm not sure what you are proposing. I don't have access to the internals of the documents which I am opening. My code which I presented is from my document handling application which is on the 'outside' of the documents. I'm simply opening these document by using server instances of Word and Excel via automation. I'm looking for a way to programmatically open these documents, while at the same time circumventing any AutoRun (or AutoExecute) macros which may be encoded into the documents. Thanks, - Joseph Geretz "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... use Private Sub Auto_Open in a general module instead of Private Sub Workbook_Open() in thisworkbook. -- Gary "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 |
#5
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]() "Jezebel" wrote in message ... Set the AutomationSecurity property to msoAutomationSecurityForceDisable before opening the file. Remember to set it back when you've finished. Use a sequence something like -- Dim pWord As Word.Application Dim pDoc As Word.Document Dim pSetting As MsoAutomationSecurity Set pWord = New Word.Application pSetting = pWord.AutomationSecurity pWord.AutomationSecurity = msoAutomationSecurityForceDisable Set pDoc = pWord.Documents.Open([FileName]) pWord.AutomationSecurity = pSetting Jezebel, You're answering the wrong question. You're describing how to open a Word document from Excel. The question was how to open an Excel workbook from Word. -- Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org |
#6
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
The example is in the wrong application - the method works in both
applications so change Word to Excel (and Document to Workbook) and it should do the trick. -- Enjoy, Tony "Jonathan West" wrote in message ... "Jezebel" wrote in message ... Set the AutomationSecurity property to msoAutomationSecurityForceDisable before opening the file. Remember to set it back when you've finished. Use a sequence something like -- Dim pWord As Word.Application Dim pDoc As Word.Document Dim pSetting As MsoAutomationSecurity Set pWord = New Word.Application pSetting = pWord.AutomationSecurity pWord.AutomationSecurity = msoAutomationSecurityForceDisable Set pDoc = pWord.Documents.Open([FileName]) pWord.AutomationSecurity = pSetting Jezebel, You're answering the wrong question. You're describing how to open a Word document from Excel. The question was how to open an Excel workbook from Word. -- Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org |
#7
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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 |
#8
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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 |
#9
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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 |
#10
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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 |
#11
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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 |
#12
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
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 |
#13
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
There seems to be some confusion here ..
When starting an *Application* (Word, Excel, etc.) via automation, automacros do NOT run. When opening a Word *Document* via automation, automacros DO run It's slightly more complicated in Excel I believe in that Workbook Events DO run but Auto_Open macros DON'T run. The Application.AutomationSecurity setting applies, AFAIK, equally to Word and Excel. -- Enjoy, Tony "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 |
#14
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
|
|||
|
|||
![]()
If using the TestOpen/Close demos with late binding and the code is say Word
would need to replace the xl constants as follows: oWB.RunAutoMacros 1& ' xlAutoOpen oWB.RunAutoMacros 2& ' xlAutoClose Regards, Peter T "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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Disable macros on a programmatically opening .xls file | Excel Discussion (Misc queries) | |||
how do I prevent a file from opening if user has disabled macros? | Excel Programming | |||
Disable Macros in workbook programmatically | Excel Programming | |||
How do I turn off macros when programmatically opening a workbook. | Excel Programming | |||
autorun code when opening sheet (not workbook) | Excel Programming |