Solved

How do I run a Word Macro From VB?

Posted on 2001-08-08
7
187 Views
Last Modified: 2012-08-14
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?
0
Comment
Question by:kenmck
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 6364545
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6365975
Call your macro "Auto_open", everytime the user loads the template macro is executed.
Cheers
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6365995
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
ID: 6365999
By the way, that macro have to be public.
Cheers
0
 

Author Comment

by:kenmck
ID: 6479149
Cheers that worked fine.

Thanks for your help.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6479939
Just a question:
If that worked fine, why a "B" grade?
Glad to help you.
Cheers.
0
 

Author Comment

by:kenmck
ID: 6479986
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now