从VBA Excel打开和关闭Word文档 [英] Open and Close Word Document from VBA Excel
问题描述
我在VBA Excel中开发了一个小程序.这是一个很好的开始,但是我调整了一些预设-一个网站建议这样做,因为它将从MS Word中提取文本.我将正在处理的所有代码都剥离了以下内容:
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
它会打开任务管理器中引用的Word文档,但不会从界面中打开.
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正在等待另一个应用程序完成OLE操作.
Microsoft Office Excel is waiting for another application to complete an OLE action.
最后,运行停止,最终出现运行时错误'-2147023170(800706be)':自动化远程调用失败.
Finally the run stops and I end up with Run-Time Error '-2147023170 (800706be)': Automation The Remote call failed.
*我已经尝试了所有基本技巧,例如关闭Excel和Word的所有实例.
*I've tried all the basic tricks such as shutting down all instances of Excel and Word.
推荐答案
您应在Set objWord = CreateObject("Word.Application")
这篇关于从VBA Excel打开和关闭Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!