从VBScript调用外部VBA [英] Calling an External VBA from VBScript
问题描述
我正在使用一个名为mathtype的程序从Word文档中提取一些方程式对象.我已经使用VBA编写了可以使用其API完美运行的代码,但是我必须将其转换为VBScript文件.我在Google各处浏览过,但是没有找到关于如何(如果可能的话)从VBScript调用VBA库的任何解决方案.
I am using a program called mathtype to pull some equation objects out of a word document. I've written code in VBA that works perfectly using their API, but I have to translate it to a VBScript file. I have looked all over google, but have not found any solution on how (If it is even possible) to call a VBA library from VBScript.
VBScript看不到MathTypeSDK对象/函数.
VBScript can't see the MathTypeSDK Objects/Functions.
如果不可能,如何将需要运行的宏封装在全局可用的word文件中,并从VBScript调用它?
If not possible, how would I encase the macro I need to run in a globally available word file and call it from the VBScript?
知道了!不幸的是,以下方法虽然有用,但不适用于我的情况.我发现更近一些:将宏嵌入到全局文件中,然后通过Word Objects Run命令调用它. objWord.Run"Normal.NewMacros.RunMain"
Got it! Unfortunately the approaches below, while helpful, did not work for my situation. I found something closer: Embedding the macro in a global file and calling it through the Word Objects Run command. objWord.Run "Normal.NewMacros.RunMain"
推荐答案
这是一种可能对您有用的方法.我测试了这个简单的例子.
Here is an approach which might work for you. I tested this simple example.
文件"Tester.docm"中的类"clsTest":
Class "clsTest" in file "Tester.docm":
Public Sub Hello()
MsgBox "Hello"
End Sub
实例"类标记为"PublicNotCreatable".
Class "Instancing" is marked "PublicNotCreatable".
"Tester.docm"中的模块:
Module in "Tester.docm":
Public Function GetClass() As clsTest
Set GetClass = New clsTest
End Function
在您的vbscript中:
In your vbscript:
Dim fPath, fName
fPath = "C:\Documents and Settings\twilliams\Desktop\"
fName = "Tester.docm"
Dim wdApp, o
Set wdApp = CreateObject("word.application")
wdApp.visible=true
wdapp.documents.open fPath & fName
Set o = wdApp.Run("GetClass")
o.Hello
Set o=nothing
再次-我只测试了这个简单的示例:您必须根据情况调整并尝试.
Again - I only tested this simple example: you'll have to adapt it to your situation and try it out.
这篇关于从VBScript调用外部VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!