在安全模式下打开 Word(从 Outlook VBA)
我有一个 Word 文档作为电子邮件的附件,我需要从中获取一些数据以传递到 URL。为此,我将附件保存到本地临时文件,然后打开文档,然后使用 Word 对象模型从文档中的表中提取数据。
在 VBA 中打开文档时,我遇到了一些问题:首先,它非常慢,因为我们有一些公司宏内容在 Word 打开时加载;其次,如果在 Word 打开时出现任何消息(例如文档恢复内容),代码就会挂起并且 Word 永远不会关闭。
所以,我的问题是我可以从 VBA 以安全模式打开 Word,这样除了基本文档之外什么都可用(因为这就是我所需要的)?或者,是否有更好的方法来控制 Word 来解决我遇到的问题?
I have a Word document as an attachment to an email that I need to get some data out of to pass to a URL. To do this I'm saving the attachment to the local temp file, then opening the document, and then using the Word object model to pull data out of tables in the document.
I'm having a couple of problems when opening the document in VBA: firstly it's very slow because we have some corporate macro stuff that loads when Word opens; and secondly if there are any messages that ping up when Word opens (such as document recovery stuff), the code just hangs and Word is never closed.
So, my question is can I open Word in safe mode from VBA so that nothing but the bare bones document is available (because that's all I need)? Or, is there a better way of controlling Word that gets around the issues I'm having?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许使用 shell 以安全模式打开,说:
"C:\Program Files\Microsoft Office\Office11\Winword.exe" /a
然后使用 GetObject 获取实例。
更多详细信息:
对于睡眠,需要位于模块顶部:
/a 启动 Word 并防止自动加载加载项和全局模板(包括 Normal 模板)。
/a 开关还锁定设置文件;也就是说,如果使用此开关,则无法读取或修改设置文件。
Perhaps use shell to open in safe mode, say:
"C:\Program Files\Microsoft Office\Office11\Winword.exe" /a
Then use GetObject to get the instance.
More details:
For Sleep, this needs to go at the top of the module:
/a Starts Word and prevents add-ins and global templates (including the Normal template) from being loaded automatically.
The /a switch also locks the setting files; that is, the setting files cannot be read or modified if you use this switch.