Solved

How do I run a Word Macro From VB?

Posted on 2001-08-08
7
189 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

821 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