从 java 代码调用 VB 宏
我创建了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Windows 附带的“cscript.exe”运行 vbscript。
根据您的场景,您可以通过多种方式从 Java 启动它:
编辑:如果您的脚本有 GUI,则使用“wscript.exe”。
我假设您指的是 vbscript,但如果您确实指的是宏,例如 Word 宏,那么您将需要执行以下操作:
或者,您可以创建一个小型 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:
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:
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.
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.
我们正在使用 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.