【发布时间】:2017-02-06 13:06:57
【问题描述】:
我目前正在使用 VBA 通过添加对库的引用来创建 word 的实例,但这会导致问题,因为存在一些没有 word 的机器。
这会导致这些机器在启动时立即出现运行时错误。无法捕获此错误。
但是,我尝试通过类似这样的方式在 VBA 中动态创建一个对象
Dim oWshShell As WshShell
Set oWshShell = New WshShell
' *** TEST REGESTRY
Dim tmp As String
tmp = oWshShell.RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\15.0\Word\Options\PROGRAMDIR")
Debug.Print tmp
tmp = tmp + "winword.exe"
Dim oWord As Object
Set oWord = Shell(tmp)
但我的问题是 oWord 不是 Word.Application 的对象。那么如何处理呢?
如果能够使用 Word.Application 等所有功能,那就太好了。
【问题讨论】: