Macro to open Word and Start Mail Merge

  • Re: Macro to open Word and Start Mail Merge


    Hi all.


    Hope you can help me, I am very new at this!


    I have an Excel workbook. I want to take certain values from said workbook and put them into a word document (basically Word outputs things more prettily!). I also need too make this as idiotproof as possible.. so my hope was to take the Excel document that I am using (I create a quote using it), and be able to hit a button which runs a macro that calls up the Word template I want to use, bungs everything into that, then gives the option to print it to pdf and then save that pdf.


    I've tried Ender's code first, which gets me as far as starting Word (good start), but won't run the mailmerge - I think because the data source I am trying to use is the Excel file I am already working in.


    Then tried Wendie's code.


    Again this starts Word, and then I get an Excel runtime error 4605 saying "This method pr property is not available because the current mailmerge main document needs a data source".


    Here's the chunk of Wendie's code it doesn't like:



    'Now you start opening the Word application and the document
    With wdApp

    ' Set wdDoc = .Documents.Open

    Set wdDoc = .Documents.Open(Filename:="K:\Projects\Quote Templates\selfbuild estimate template.docx") '<==this opens the document so you can manipulate it.
    wdDoc.Application.Visible = True


    ' Just telling word how to run the merge


    With wdDoc.mailmerge
    .MainDocumentType = wdFormLetters
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True
    .Execute Pause:=False

    End With



    .....and from there on.



    Why not just open the word file manually and merge from there? Because the person generating the quote will already be working with an excel file, and I need to generate 4 different kinds of quote depending on the type of customer. So it makes more sense to do it from Excel than from Word.


    I think basically I need to tell Word to use the open Excel workbook as the datasource... help... please!!

  • Re: Macro to open Word and Start Mail Merge


    Hi thorn1979, welcome to Ozgrid.


    Please do not post your own question in another thread - this is known as thread-hijacking and is against the rules. Please start your own thread for you question, and provide a link to this one if you feel it would help. Also please note the rules regarding code tags.


    If you are unsure on any of the above please feel free to ask.


    Kind Regards,


    S O

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!