Results 1 to 1 of 1

Assistance with a simple Mail Merge macro

Threaded View

  1. #1
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    136

    Assistance with a simple Mail Merge macro

    Hi All,

    I am trying to run a simple mail merge using a quick access toolbar button to open an existing word template with all merge fields set up ready to go and already pointing to an excel data template. This procedure is done after first running another macro that sets up and saves the excel data template. I hope to combine the two macros into one once I can get the mail merge macro to function.

    The excel data template is located at: G:\CAT Post Sale Quote Request Mail Merge\Post Sale Ship Request Data Template.xlsx
    The word mail merge template is located at: G:\CAT Post Sale Quote Request Mail Merge\Post-sale Ship Request Email Template.docx

    I have the following code that I do not fully understand except for the possible error in placement of the excel and word file locations:
    Sub RunMailMerge()
    
        Dim wdOutputName, wdInputName As String
        wdOutputName = ThisWorkbook.Path & "G:\CAT Post Sale Quote Request Mail Merge\Post-sale Ship Request Email Template.docx"
        wdInputName = ThisWorkbook.Path & "G:\CAT Post Sale Quote Request Mail Merge\Post Sale Ship Request Data Template.xlsx"
    
        ' open the mail merge layout file
        Dim wdDoc As Object
        Set wdDoc = GetObject(wdInputName, "Word.document")
        wdDoc.Application.Visible = True
    
        With wdDoc.MailMerge
             .MainDocumentType = wdFormLetters
             .Destination = wdSendToNewDocument
             .SuppressBlankLines = True
             .Execute Pause:=False
        End With
    
        ' show and save output file
        wdDoc.Application.Visible = True
        wdDoc.Application.ActiveDocument.SaveAs wdOutputName
    
        ' cleanup
        wdDoc.Close SaveChanges:=False
        Set wdDoc = Nothing
    
    End Sub
    I have trawled for days and clicked many links looking for the answer to this. The above code appeared to be the most straight forward approach if only I could adapt it to my file locations.

    I'm not sure why I would need to access the excel file as the word template already looks for the data file.....

    Can someone please point out where I am going wrong and/or what it is I am missing?

    Many thanks,
    Last edited by L plates; 03-12-2015 at 09:38 AM. Reason: additional info added
    Dave C

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Running Word Mail Merge from Excel 2010 - Mail Merge workbook fails
    By pl05.lau@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-05-2015, 07:35 AM
  2. Replies: 2
    Last Post: 07-12-2012, 08:11 PM
  3. Basic Mail Merge Assistance
    By cully1234 in forum Excel General
    Replies: 1
    Last Post: 02-16-2010, 06:32 PM
  4. Mail Merge Macro?
    By beth2013 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2009, 01:26 AM
  5. [SOLVED] Mail merge assistance please
    By Kevin J Prince in forum Excel General
    Replies: 2
    Last Post: 05-14-2006, 12:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1