Merge it with MS Word

Shannon

Registered User.
Local time
Today, 13:38
Joined
Dec 12, 2001
Messages
14
I have been trying to create a macro that will select a query, start Merge it with MS Word, than perform a macro in Word. Is this possible? Any help would be GREATLY APPRECIATED! The ending product is a letter with the export data while keeping the format. I can do it but my users will not be able to do it. That is why I would like to create a macro that will do it all. HELP PLEASE!!!
 
This is a task for VBA.

Goto the modules tab and post this code. Alter the name of the document to your merge doc which should have its control source set to the query or table in your database you need.


Function Merge()

Dim oApp As Object

Set oApp = CreateObject("Word.Application")

oApp.Visible = True

With oApp
'alter the path below to the doc location
.Documents.Open "C:\My Documents\somewhere.doc"
.ActiveDocument.MailMerge.Execute

'the following lines are optional
'.ActiveDocument.PrintOut
'Background:=False
' Close the document without saving changes.
'.ActiveDocument.Close
'SaveChanges:=wdDoNotSaveChanges
' Quit Microsoft Word 97 and release the object variable.
'.Quit

Set oApp = Nothing


End With

End Function


On the command button that you had set to run your macro:

Instead of RunMacro for the OnClick event, type =Merge()

Good luck!
 
Thank You so much! I going to give it try!

Shannon
 

Users who are viewing this thread

Back
Top Bottom