【发布时间】:2020-08-28 05:56:11
【问题描述】:
我目前正在尝试使用 VBA 从 Microsoft Excel 打开 Microsoft Word。我在网上找到了这些资源:
基于它们,我想出了以下代码:
代码 1
Dim wordApp As Word.Application
Set wordApp = CreateObject("Word.Application")
在 Word 已打开的情况下运行代码
Excel 停止响应。
关闭 Word 运行代码
Word 打开,但 Excel 给我错误 Out of memory 或 Automation error 和 wordApp 未定义。
代码 2
Dim wordApp As Word.Application
Set wordApp = GetObject(,"Word.Application")
在 Word 已打开的情况下运行代码
Excel 抛出错误 Out of memory 和 wordApp 未定义。
关闭 Word 运行代码
Excel 抛出错误 ActiveX component can't create object or return reference to this object 和 wordApp 未定义。
系统信息
操作系统:macOS Mojave (10.14.6)
Excel 和 Word 版本:16.36
Excel 中的引用:
Visual Basic For Applications, Microsoft Excel 16.0 Object Library, Microsoft Forms 2.0 Object Library, Microsoft Office 16.0 Object Library, Microsoft Word 16.0 Object Library, OLE Automation
结论
这些错误非常令人困惑,我无法通过阅读 Microsoft 的错误页面来修复它们。例如,我不断收到错误Out of memory(见上文),尽管我有大约 10 GB 的可用 RAM 空间。我怎样才能让它在我的机器(见上文)以及任何其他机器上可靠地工作?
【问题讨论】:
标签: excel vba automation ms-word