Open and Close Word Document from VBA Excel

▼魔方 西西 提交于 2019-12-13 03:44:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!