使用Word自动化,是否可以查明活动文档是否包含VBA代码?
使用 Word Automation,我想以编程方式保存活动文档。在 Office 2007/2010 中,需要将文档显式保存为“启用宏”,以保留该文档中的任何 VBA 代码。
我希望我的应用程序能够确定活动文档中是否有 VBA 代码,而不是要求用户进行选择。这可能吗?
Using Word Automation, I want to save the active document programmatically. In Office 2007/2010, the document needs to be saved explicitly as "macro enabled" to preserve any VBA code in that document.
Rather than asking the user to choose, I would like my application to be able to determine if there is VBA code in the active document. Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这可以通过
HasVBProject
属性确定。例如:对于那些稍后可能偶然发现这篇文章的人,值得注意的是,该代码应放置在正在测试宏是否存在的文档之外(否则它会检测自身)。两个常用的选项是从外部应用程序或从存储在 Word 的启动文件夹中的模板访问代码。
Yes this can be determined via the
HasVBProject
property. For example:For those who might stumble upon this post later, it is worth noting that this code should be placed outside the document being tested for the presence of macros (otherwise it would detect itself). Two often-used options would be to access the code from an external application or from a template stored in Word's Startup folder.