Calling external VBA from VBScript

I am using a program called mathtype to pull some equation objects from a text document. I wrote code in VBA that works fine with their API, but I have to translate it into a VBScript file. I went through all of Google, but did not find a solution on how (if possible) to call the VBA library from VBScript.

VBScript cannot see MathTypeSDK objects / functions.

If this is not possible, how can I enclose a macro that I need to run in a globally accessible word file and call it from VBScript?

Edit: succeeded! Unfortunately, the approaches below, although useful, did not help me in my situation. I found something closer: embedding a macro in a global file and calling it through the command to run Word objects. objWord.Run "Normal.NewMacros.RunMain"

+3
source share
2 answers

Word-VBA was not created to create reusable libraries, I suppose (for use in external programs).

One way to reuse existing Word-VBA code, however, launches Word through WScript.Shell.Runusing the command line switch /m<macroname>(see http://support.microsoft.com/kb/210565/en-us ). This has a limitation that is required in order to invoke a specific macro; the Word process starts again, starts this macro and ends later. So if you only need one call to your Word.VBA for a specific task, that might be fine, but if you need a lot of interprocess communication between your VBScript and your VBA macro, you should look for another solution.

+2

, . .

"clsTest" "Tester.docm":

Public Sub Hello()
    MsgBox "Hello"
End Sub

"Instancing" "PublicNotCreatable".

"Tester.docm":

Public Function GetClass() As clsTest
    Set GetClass = New clsTest
End Function

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

- : .

+2

All Articles