starting Word with an Excel macro



I found this piece of code that opens Word from within an Excel macro
Private Sub Open_word_run_build_directory()
Dim oWord As Object
Dim oDoc As Object
Dim wpath As String
wpath = ActiveWorkbook.Path
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oDoc = oWord.Documents.Open(wpath & "\build directory V6.doc")
End Sub

The Word doc ‘build directory V6.doc’ has a VBA macro in an AutoOpen
subroutine that executes when it opens. Everything works fine except Excel
closes after executing the above routine. I would like it to stay open.
Nothing in the Excel code that follows the above subroutine is the cause of
Excel closing so I have to assume that something about this routine is
causing it or perhaps Excel VBA and Word VBA cannot execute at the same time.
Any thoughts on this?




There is nothing in the code you posted that would cause Excel to close.
Did you check the Document.Open event of your word document to see if it has
something that might close other applications?



Barb Reinhardt

If you don't want code to run when you open a doc, put this around the code
where you open the document

oWord.AutomationSecurity =msoAutomationSecurityLow
oWord.AutomationSecurity = msoAutomationSecurityByUI

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question