(Solved) – Running a MS Word mail merge from excel

  • by
(solved)-–-running-a-ms-word-mail-merge-from-excel

I know this has been asked before and I tried to update the other thread but was not allowed.

I have a spreadsheet that has data that is used in a MS mail merge. I have a Word mail merge document that is all set up to run. The fields are already set up. When I open the word doc I get a prompt that says “Opening this document will run the following SQL command”, etc, etc. What I want to do is have the Excel spreadsheet run the mail merge without any user intervention when I click a button. I put together the following code from examples on this forum but is not working. When run Word opens and I get the same prompt. How do I get this to work?

Public Sub RunMailMerge(MMFileName As String)

    Dim wdDoc As Object

'   open the mail merge layout file

    Set wdDoc = GetObject(MMFileName, "Word.document")
    wdDoc.Application.Visible = True

    With wdDoc.MailMerge
         .MainDocumentType = wdFormLetters
         .Destination = wdSendToPrinter
         .SuppressBlankLines = True
         .Execute Pause:=False
    End With

'   cleanup

    wdDoc.Close SaveChanges:=False
    Set wdDoc = Nothing

End Sub

Also all of the examples I have seen use late binding. Wouldn’t it better to use early bind of the word object?

Thanks
Don

Leave a Reply

Your email address will not be published. Required fields are marked *