Anyone know how to open a document in Word(97) and then run a set of macros in it?
Printable View
Anyone know how to open a document in Word(97) and then run a set of macros in it?
Add the Microsoft Word 8.0 Object library (using References) to your VB project. Then;
Make sure you have installed the "Help for Visual Basic" options for Office '97 - it's not installed by default. This will give you the comprehensive help file that you can use with the Word objects.Code:'start a Word application object
Dim objWord As New Word.Application
Dim objDoc As Word.Document
'if you want Word to be visible during operation use this line
objWord.Visible = True
'load the document
Set objDoc = objWord.Documents.Open("[filename]")
'run the Macro
objWord.Run "Macro1"
'then to close the document (without saving changes)
'use objDoc.Save or .SaveAs to save the document.
objDoc.Close False
'and quit Word...
objWord.Quit
Set objWord = Nothing