Solved

Run word mailmerge from Access

Posted on 2014-02-07
8
860 Views
Last Modified: 2014-05-10
Dear Experts,

As part of a bigger project I need to be able to do the following from Access.

Open up an already prepared word email mailmerge doc and run the mail merge.

Please note the email addresses for the mailmerge is already linked up to the word doc & has nothing to do with the access database.

Can anybody help?
0
Comment
Question by:correlate
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
Albert D. Kallal has a truly great mail merge sample, I'm not sure what exactly you need so this may be a bit of an overkill, but it is definitely worth looking at!

http://www.kallal.ca/wordmerge/index.html
0
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
If all you want is to open a ready made mailmerge document and execute the merge try this (not tested):

Sub Demo()

   Dim StrFullDocPath As String
   Dim oApp As Object
   
   'Path to the word document
   StrFullDocPath = "C:\Test\TestDocument.docx"
   
   If Dir(StrFullDocPath ) = "" Then
      MsgBox "Document not found."
   Else
      'Create an instance of MS Word
      Set oApp = CreateObject("Word.Application")
      oApp.Visible = True
      
      'Open the Document
      oApp.Documents.Open filename:=StrFullDocPath 
   End If

   With oApp
      With .MailMerge 
         .Destination = wdSendToNewDocument 
         .Execute          
      End With
   End With

   oApp.Close
   Set oApp = Nothing

End Sub

Open in new window

0
 

Author Comment

by:correlate
Comment Utility
Thanks for this - you code above looks like it will do exactly what I'm after, I have tried it but unfortunately I got an error (438 - Object doesn't support this property or method) - it highlights       With .MailMerge - looking at the code it looks like its trying a document rather than an email mailmerge?

Any ideas
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
HI,

pls try

   With oApp
      With ActiveDocument.MailMerge 
         .Destination = wdSendToNewDocument 
         .Execute          
      End With
   End With

Open in new window

Regards
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:correlate
Comment Utility
HI thanks for that

Alas I'm getting "Object required" pointing to this line ..

      With ActiveDocument.MailMerge
0
 
LVL 26

Accepted Solution

by:
MacroShadow earned 400 total points
Comment Utility
Try this (once again not tested):

Sub Demo()

    Dim StrFullDocPath As String
    Dim oApp As Object
    Dim oDoc As Object

    'Path to the word document
    StrFullDocPath = "C:\Test\TestDocument.docx"

    If Dir(StrFullDocPath) = "" Then
        MsgBox "Document not found."
    Else
        'Create an instance of MS Word
        Set oApp = CreateObject("Word.Application")
        oApp.Visible = True

        'Open the Document
        Set oDoc = oApp.Documents.Open(FileName:=StrFullDocPath)
    End If

    'Merge to email
    If oDoc.State = wdMainAndSourceAndHeader Or oDoc.State = wdMainAndDataSource Then
        With oDoc.MailMerge
            .Destination = wdSendToEmail
            .Execute
        End With
    End If

    'Clean-up
    oDoc.Close
    oApp.Close
    Set oDoc = Nothing
    Set oApp = Nothing

End Sub

Open in new window

0
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 100 total points
Comment Utility
hi.

forgot the point

With oApp
      With .ActiveDocument.MailMerge 
         .Destination = wdSendToNewDocument 
         .Execute          
      End With
   End With

Open in new window

Regards
0
 

Author Closing Comment

by:correlate
Comment Utility
Brilliant, thank you for your help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

763 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

9 Experts available now in Live!

Get 1:1 Help Now