为什么使用Office Automation从Delphi打开文档时,Document_open宏不在单词中运行
我正在尝试使用Delphi Tokyo的办公自动化打开Word文档(使用Word 2016)。该文档具有Document_open宏,该宏可提示用户可选地运行另一个宏。
当我运行以下代码时: -
Doc := IDispatch(WordApp.Documents.Open([*filename*])) as _Document;
文档打开,但是document_open宏未运行。 ,如果我尝试手动运行第二个(主)宏,我会遇到一个错误,说“该项目中的宏已禁用...”
另外 预期,因此显然没有残疾。
VBA项目是数字签名的,单词设置为“禁用除数字签名宏以外的所有宏”。
从Delphi内打开文档时,如何使宏可以运行?
I am trying to use Office Automation in Delphi Tokyo to open a Word document (using Word 2016). The document has a Document_Open macro that prompts the user to optionally run another macro.
When I run the following code:-
Doc := IDispatch(WordApp.Documents.Open([*filename*])) as _Document;
the document opens, but the Document_Open macro does not run. Also, if I try to run the second (main) macro manually, I get an error saying "The macros in this project are disabled ..."
However, if I open the same document from the Word file menu, the macros run as expected, so they are clearly not disabled.
The VBA project is digitally signed and Word is set to "Disable all macros except digitally signed macros".
How do I get my macros to run when opening the document from within Delphi?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Braknicku带领我找到了答案。
我发现,除非您设置WordApp。
因此,我问题的答案是: -
然后,只要用户的信任设置允许宏运行,它将!
我希望这对某人有帮助。
BrakNicku led me to the answer.
I have found that unless you set WordApp.AutomationSecurity to msoAutomationSecurityByUI, macros are disabled irrespective of the settings in Word.
So the answer to my question is:-
Then, provided the user's Trust Settings allow the macro to run, it will!
I hope this helps someone.