简体   繁体   English

使用 Perl 将 VBA 代码添加到 MS Word 文档

[英]Add VBA code to a MS Word document using Perl

I have a Perl script that can define and write MS Word VBA according to the user's input.我有一个 Perl 脚本,可以根据用户的输入定义和编写 MS Word VBA。

How can I make the Perl script open Word and add the VBA code into its code data base?如何让 Perl 脚本打开 Word 并将 VBA 代码添加到其代码数据库中?

You can do that by accessing the VBProject property of the document.您可以通过访问文档的VBProject属性来做到这一点。 However, with recent versions of Microsoft Office, you will likely get:但是,使用最新版本的 Microsoft Office,您可能会获得:

OLE exception from "Microsoft Word":

Programmatic access to Visual Basic Project is not trusted.

See You may receive an run-time error when you programmatically allow access KB article for more information.有关详细信息,请参阅以编程方式允许访问知识库文章时,您可能会收到运行时错误

Or, you can try to do it the primitive way by sending keystrokes to Word using Win32::GuiTest .或者,您可以尝试通过使用Win32::GuiTest将击键发送到 Word 来尝试以原始方式进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM