+ Reply to Thread
Results 1 to 2 of 2

Using Multiple Mail Merge Templates in one Macro

Hybrid View

SharifB88 Using Multiple Mail Merge... 11-25-2014, 01:49 PM
SharifB88 Re: Using Multiple Mail Merge... 11-25-2014, 07:45 PM
  1. #1
    Registered User
    Join Date
    11-25-2014
    Location
    Canada
    MS-Off Ver
    MS Office 2010
    Posts
    9

    Using Multiple Mail Merge Templates in one Macro

    I am using multiple mail merge templates to create contracts in Microsoft Word. Right now I have 3 buttons with 3 different mail merge templates.

    Is there a way to combine these 3 buttons into 1 so I can create 3 different contracts one after another without having to press the other 2 buttons?
    When I try to combine all three using call I receive an error saying that the template can not be found. Is it because I have already a template open?

    Note: I changed some of the file locations so dont worry if they look wrong


    Sub MergeMe2()



    Dim bCreatedWordInstance As Boolean
    Dim objWord As Word.Application
    Dim objMMMD As Word.Document
    Dim cDir As String
    Dim ThisFileName As String
    Dim NewFileName As String

    Const WTempName = "Contract Template.docx" 'This is the 07/10 Word Templates name, Change as req'd

    cDir = "I:\Accounts Payable" 'Change if appropriate
    ThisFileName = ThisWorkbook.Name

    On Error Resume Next

    bCreatedWordInstance = False
    Set objWord = GetObject(, "Word.Application")

    If objWord Is Nothing Then
    Err.Clear
    Set objWord = CreateObject("Word.Application")
    bCreatedWordInstance = True
    End If

    If objWord Is Nothing Then
    MsgBox "Could not start Word"
    Err.Clear
    On Error GoTo 0
    Exit Sub
    End If

    On Error GoTo 0

    objWord.Visible = True

    Set objMMMD = objWord.Documents.Open("AccountsPayable.docx")
    objMMMD.Activate

    With objMMMD
    .MailMerge.OpenDataSource Name:="I:\AccountsPayable.xlsm", sqlstatement:="SELECT * FROM `Export`"
    With objMMMD.MailMerge 'With ActiveDocument.MailMerge
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True
    With .DataSource
    .FirstRecord = objMMMD.MailMerge.DataSource.ActiveRecord
    .LastRecord = objMMMD.MailMerge.DataSource.LastRecord
    End With
    .Execute Pause:=False
    End With
    End With

    objWord.ActiveDocument.SaveAs cDir + NewFileName

    objMMMD.Close savechanges:=wdDoNotSaveChanges
    Set objMMMD = Nothing

    If bCreatedWordInstance Then
    objWord.Quit
    End If

    0:
    Set objWord = Nothing

    End Sub

  2. #2
    Registered User
    Join Date
    11-25-2014
    Location
    Canada
    MS-Off Ver
    MS Office 2010
    Posts
    9

    Re: Using Multiple Mail Merge Templates in one Macro

    any help on this one?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 07-12-2012, 08:11 PM
  2. Mail Merge macro for Multiple Emails
    By kt090678 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2011, 03:51 AM
  3. How to use multiple record in Mail Merge
    By kushalprakash in forum Excel General
    Replies: 2
    Last Post: 12-05-2006, 02:16 AM
  4. [SOLVED] How do I mail merge using multiple worksheets?
    By StarWars in forum Excel General
    Replies: 1
    Last Post: 07-27-2006, 03:45 AM
  5. Mail merge - Multiple entries
    By conksu in forum Excel General
    Replies: 12
    Last Post: 03-02-2006, 03:15 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