从 java 代码调用 VB 宏

发布于 2024-08-31 23:58:44 字数 59 浏览 3 评论 0原文

我创建了一个 VB 宏。我想向宏传递一个字符串和一个文件位置。我如何在java代码中调用它。有这个库吗?

I have a VB macro created. I want to pass the macro a string and a file location. How would I call this in java code. Is there a library for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌若浮生 2024-09-07 23:58:44

您可以使用 Windows 附带的“cscript.exe”运行 vbscript。

根据您的场景,您可以通过多种方式从 Java 启动它:

  • 使用 Runtime.exec 启动程序。您可以直接将其作为程序的一部分来执行。
  • 使用具有 exec 任务的 Ant,或具有 exec 插件的 maven。当作为构建或其他批处理过程的一部分调用脚本时,这非常有用。

编辑:如果您的脚本有 GUI,则使用“wscript.exe”。

我假设您指的是 vbscript,但如果您确实指的是宏,例如 Word 宏,那么您将需要执行以下操作:

"C:\Program Files\Microsoft Office\Office12\Winword.exe" 
"C:\MyPath\MyDoc.doc" /m"Macro1"

或者,您可以创建一个小型 vbscript 来实例化 Word 应用程序并使用 run( ) 方法来调用宏。您可以使用 cscript.exe/wscript.exe 执行该脚本。

You can run vbscript using the "cscript.exe" that ships with windows.

Depending upon your scenario, you can launch this from Java in a variety of ways:

  • use Runtime.exec to launch the program. You can do this directly as part of your program.
  • use Ant, which has an exec task, or maven which has an exec plugin. This is most useful when invoking the script as part of a build or some other batch process.

EDIT: If your script has a GUI, then use "wscript.exe".

I'm assuming you mean vbscript, but if you reall mean a macro, such as a Word macro, then you will need to do something like this:

"C:\Program Files\Microsoft Office\Office12\Winword.exe" 
"C:\MyPath\MyDoc.doc" /m"Macro1"

Alternatively, you can create a small vbscript that instantiates the Word Application and uses the run() method to invoke a macro. You execute that script using cscript.exe/wscript.exe.

煮茶煮酒煮时光 2024-09-07 23:58:44

SourceForge 上有“JACOB - Java COM Bridge”。该项目有第二个更过时的主页

还有一个名为 J-Integra 的商业 (D)COM/ActiveX 自动化库,它也看起来它可以做这样的事情。

免责声明:这些只是我从 Google 中提取的链接,我对这些库没有任何实际经验。

There is the "JACOB - Java COM Bridge" on SourceForge. The project has a second, more dated homepage.

And then there is a commercial (D)COM/ActiveX automation library called J-Integra, which also looks like it could do such a thing.

Disclaimer: Those are just links I've pulled out of Google, I have no practical experience with these libraries.

感悟人生的甜 2024-09-07 23:58:44

我们正在使用 Com4J,它为我们创建了一组 Java 类,这些类看起来与 Word VBA 中可用的 ActiveX 类相同,并直接调用它们。这显然只适用于 Windows 机器,因为 Word 不能在 Linux 上运行(除非你有很多时间和 Wine)。

通过在 Java 中准备好这些 API,我们将能够调用在 word 中定义的任何宏。

We are using Com4J, which created us a set of Java Classes which looks identical to the ActiveX classes usable from Word VBA, and call those directly. This obviously only works on Windows machines, since Word does not run on Linux (except for when you have much time and Wine).

By having these APIs ready in Java, we would be able to call any macro defined in word.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文