View Full Version : Solved: vbscript call to VBA Word macros?

01-08-2005, 06:14 AM
Hi, Sorry to be a non-programmer here; I presumed it would be esay, but just cannot find how (if possible) to call a Word macro from a vbscript; can it be done anyway?
Thanks, Randall

01-18-2005, 02:22 AM
Here's an example:

Dim Word
Dim WordDoc
Set Word = CreateObject("Word.Application")

' Make Word visible
Word.Visible = True

'Open the Document
Set WordDoc = Word.Documents.open("c:\adocument.doc")

'Run the macro called foo
Word.Run "foo"

' Close Word
'Release the object variables
Set WordDoc = Nothing
Set Word = Nothing


01-21-2005, 06:45 PM
Thanks so much; I have now managed to call a macro taken from this site (making a list of files; Showlist). Is it possible to keep Word hidden and close after running, or even only open VBA and not Word??)

Thanks again, Randall

Jacob Hilderbrand
01-21-2005, 07:03 PM
Word.Visible = True
That line makes Word visible. Just remove it if you want to keep Word hidden.

01-22-2005, 01:57 AM
You can't open vba on it's own, it requires a host application, in this case word.

To keep Word from showing, comment out the line Word.Visible = True.

If you're going to do that, I'd turn on error handling (On Error Resume Next) to ensure the Word application closes, although that depends on how well your Word macro handles errors too.

You could also trap errors and report them using the Err object. There's a reasonable vbscript write up on error trapping here:


01-28-2005, 04:52 AM
:friends: Hi, thanks!

What about using "Getobject" instead of "CreateObject" if Word is already running? Would that work just as well?

Thanks, Randall