How do I run a Word Macro From VB?

I have a Word template with a macro. This macro makes the report and sends it to the printer.

Does anyone know a way from VB that I can open this template and run the macro automatically?
kenmckAsked:
Who is Participating?
 
Richie_SimonettiConnect With a Mentor IT OperationsCommented:
By the way, that macro have to be public.
Cheers
0
 
daffyduck14milCommented:
Yes, you can do it this way:

Make sure you reference the microsoft word object library. Then, using your word object you can use the wdObject.Documents.Add("C:\PathtoTemplate\Template.dot")

Then, you can use wdObject.Run MacroName:="TheMacroThatDoesTheJob"

If you have instantiated word and it's standing by with the template open that has the macro, it should run fine.

Grtz.©

D.
0
 
Richie_SimonettiIT OperationsCommented:
Call your macro "Auto_open", everytime the user loads the template macro is executed.
Cheers
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Richie_SimonettiIT OperationsCommented:
Sorry, call your macro like this (from whitin your template):

Private Sub Document_New()
Call Auto_Open ' Or whatever you name your macro
End Sub
0
 
kenmckAuthor Commented:
Cheers that worked fine.

Thanks for your help.
0
 
Richie_SimonettiIT OperationsCommented:
Just a question:
If that worked fine, why a "B" grade?
Glad to help you.
Cheers.
0
 
kenmckAuthor Commented:
I have the problem of having to make VB wait till Word has opened before it can pass the variables. It works fine but will be better I am assured when using .net.

Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.