Solved

How do I run a Word Macro From VB?

Posted on 2001-08-08
7
188 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

803 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