Excel VBA Does Not Execute Code in Order when Opening Word Document
I have been working on a macro to open a word document and write information to it. I am finding that for some reason, the word document is being opened before the macro even starts!
For example:
Code:
Sub ExampleCode()
msgbox "beginning of macro"
.
.
.
wDoc ="[file path]"
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(wDoc)
objWord.Visible = True
objDoc.Application.Activate
objWord.ActiveWindow.View.ReadingLayout = False
When running the macro, the word document will open first, then I will get the message box. Any help?
Re: Excel VBA Does Not Execute Code in Order when Opening Word Document
Quote:
then I will get the message box
try doevents after the msgbox, though it should not be needed
Re: Excel VBA Does Not Execute Code in Order when Opening Word Document
Quote:
Originally Posted by
westconn1
try doevents after the msgbox, though it should not be needed
No change, same as before.
Re: Excel VBA Does Not Execute Code in Order when Opening Word Document
i tested with your code, the msgbox shows first then i get file not found for the invalid wdoc when objword tries to open the document, this all seems correct to me, i do not know how anyone else can test with a problem that seems specific to you machine
Re: Excel VBA Does Not Execute Code in Order when Opening Word Document
Quote:
Originally Posted by
westconn1
i tested with your code, the msgbox shows first then i get file not found for the invalid wdoc when objword tries to open the document, this all seems correct to me, i do not know how anyone else can test with a problem that seems specific to you machine
I figured this one out, it wasn't VBA related. A cell had conflicting hyperlinks... I fixed the hyperlink and the problem was solved.