Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VB to execute a Word macro

Status
Not open for further replies.

samvonac

Programmer
May 18, 2001
8
US
I want to use a VB app to open a word doc and launch a macro. I have the
following code:

Sub Main()
Dim docsObj As Word.Documents
Dim docObj As Word.Document
Dim appWord As Word.Application
Set appWord = CreateObject("word.application")
Set docsObj = appWord.Documents
Set docObj = docsObj.Open("C:\mydoc.doc")
docObj.Application.Run ("MyMacro")
docObj.SaveAs "MyNewName.doc"

On Error Resume Next

docObj.Close

On Error GoTo 0

Set docsObj = Nothing
Set docObj = Nothing
appWord.Quit
End Sub


I get an error when it gets to "docObj.Application.Run ("MyMacro")" saying that
macro could not be found. I know that the macro exists and the macro is saved in
normal.dot.

I am using VB6 and Word2000. Any ideas?

Thanks in advance.
 
Hi,

You just need to specify first the name of the word document followed by the name of the macro, like:

Application.Run("MyDoc.doc!MyMacro)

Try this ;-)
 
Thanks Bib but that didn't seem to work either.

The exact error msg is:

Run-time error '-2147352573 (80020003)':
Unable to run specified macro

Any idea what could be wrong?
 
Hi,

I checked the KB and your problem is known. It says:

"WD2000 When you attempt to create a Web page using the Web Page Wizard from Word 97, the following error message may appear:
Run-time error '-2147352573 (80020003)': Unable to run the specified macro "

Is it what you're trying to do?

Check the Q220302, you may find answers to your problem.
Let me know if it helps.

Bib
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top