Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Access to Run Word Macro 1

Status
Not open for further replies.

Kamstars

Programmer
Dec 3, 2003
6
US
Currently I am opening a word document called Letter. In that word document I have a macro saved called mcrPerformMerge. Once the word document is open I want to run that macro. Is there a way? I have the section of code commented out below where I thought it should go. The word Run doesn't work alone, what should I put there?

Sub OpenWord()

Dim WordDoc As String
Dim WordApp As String
Dim FullPath As String

WordDoc = "H:\MyDocuments\Letter.doc"
WordApp = "G:\Office97\Office\WINWORD"
FullPath = WordApp & " " & WordDoc

Call Shell(FullPath, vbNormalFocus)

'Run ("Letter.doc!Project.NewMacros.mcrPerformMerge")

End Sub


Thanks for you help.
 
You need to create an application variable of the word program, though not sure if you are working within the same version of Office or not, but I'm assuming you are for now, which means, you can get by with Early Binding method.

For this to work, you must have a reference set within Access VBA to "Microsoft Word Object x.0 Library"

Dim wdApp as New Word.Application, Doc as Document
Set Doc = wdApp.Documents.Open("H:\MyDocuments\Letter.doc")
Doc.NewMacros.mcrPerformMerge

When you are done, perform the following codes at the minimal:

Doc.Close
wdApp.Close

Please note:

I'm assuming that NewMacros is the name of the module within the document, "Letter.doc" and you are wanting to run the macro, "mcrPerformMerge" within the "NewMacros" module.

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
When the going gets tough, the tough gets going.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top