Solved

How do I run a Word Macro From VB?

Posted on 2001-08-08
7
186 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
Comment Utility
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
Comment Utility
Call your macro "Auto_open", everytime the user loads the template macro is executed.
Cheers
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 16

Accepted Solution

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

Author Comment

by:kenmck
Comment Utility
Cheers that worked fine.

Thanks for your help.
0
 
LVL 16

Expert Comment

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

Author Comment

by:kenmck
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

13 Experts available now in Live!

Get 1:1 Help Now