Englishman Bob
Englishman Bob

Reputation: 483

Open and Close Word Document from VBA Excel

I developed a small program in VBA Excel. It was a good start however I adjusted some presets -- a website recommended this as would be pulling text from MS Word. I stripped out all of the code I was working on to the following:

Function FnOpeneWordDoc()

   Dim objWord

   Dim objDoc

   Set objWord = CreateObject("Word.Application")

   Set objDoc = objWord.Documents.Open("C:\Users\Filepath\Example1.docx")

   objWord.Visible = True

End Function

It opens a Word document referenced in the task manager, but not from the interface.

The program above hangs for a while and returns a the following:

Microsoft Office Excel is waiting for another application to complete an OLE action.

Finally the run stops and I end up with Run-Time Error '-2147023170 (800706be)': Automation The Remote call failed.

*I've tried all the basic tricks such as shutting down all instances of Excel and Word.

Upvotes: 1

Views: 7006

Answers (1)

Michael Murphy
Michael Murphy

Reputation: 422

You should add objword.Visible = True right after Set objWord = CreateObject("Word.Application")

Upvotes: 3

Related Questions