问题
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.
回答1:
You should add objword.Visible = True
right after Set objWord = CreateObject("Word.Application")
来源:https://stackoverflow.com/questions/51369408/open-and-close-word-document-from-vba-excel