|
|
|
|
|
|
Word
|
Automating Mail Merge
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000
|
Submitted by:
|
mdmackillop
|
Description:
|
Creates the merged document automatically when the mail merge document is opened and closes down the main document.
|
Discussion:
|
Creates the final merged document when the mailmerge is called from another application, (typically Access or Excel), once the data has been written. Once the Public Sub below has been saved in Normal.dot, any mailmerge document can be automated by adding the DoMailMerge code to the MailMerge main document as detailed.
|
Code:
|
instructions for use
|
Private Sub Document_Open()
DoMailMerge
End Sub
Public Sub DoMailMerge()
Dim DocName$
DocName = ActiveDocument.Name
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Windows(DocName).Close wdDoNotSaveChanges
End Sub
|
How to use:
|
- Copy the code above.
- Open the MailMerge document.
- Hit Alt+F11 to open the Visual Basic Editor.
- Double-click Project Normal at the left.
- Choose Insert-Module, and paste the Public Sub code into the window at the right.
- Hit the Save diskette button and close the VBE.
- Double-click the MailMerge Project at the left.
- Double-click MicrosoftWordObjects.
- Double-click ThisDocument
- Paste the Private Sub code into the window at the right.
- Hit the Save diskette button and close the VBE.
- To edit the document or the code, hold down Shift when opening the document to prevent the macro from running
|
Test the code:
|
- Close and reopen the mailmerge document. A new FormLetters document should be created containing the merged information.
|
Sample File:
|
No Attachment
|
Approved by Anne Troy
|
This entry has been viewed 274 times.
|
|