Consulting

Results 1 to 4 of 4

Thread: Solved: Help with Automating Mail Merge

  1. #1

    Question Solved: Help with Automating Mail Merge

    I am an extreme newbie on Office Products. I am using Word2003 with a txt file for the mailmerge datasource.

    I have tried to step through the
    Automating Mail Merge KB article - ran into the SQLSecurityCheck issue, and fixed that.

    When I open the word document after saving the macros, nothing happens. The file looks just like it looked when I saved it before adding the macros.

    Here is the file that I am using for testing....

    July 27, 2005



    ?Salutations? ?Title? ?LastName?,



    Thanks for the $?DonationAmount?.

    ------------------------------------

    The variables above all appear in my merge txt file.

    Thank you in advance for any help that you may be able to give me.

    Teresa

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi and welcome to vbax!

    Ok you are not telling exactly what you have done...
    So I'm going to try to tell how I think you should have done things to get the automation done. (From the top so I could miss out on stuff)
    • First Open Word
    • Go to Tools | Macro | Security
    • Second Tab set securtiy to medium!! (Important)
    • Now open your mailmerge document.
    • Can you do a manual mailmerge? Answer yes? Great your up for the code. Answer No? Wel attach your database (Txtfile) to the document and try out things manually first. All Ok? let's proceed.
    • Now Open the editor Press ALT+F11
    • You should see the project explorer on your left. Not? (Press CTRL+R)
    • Now click on the + sign next to the project that has the same name as your document: eg Project mailmerge
    • The Word objects will unfold.
    • Double click on Class Module ThisDocument
    • Paste this code in the code pane: (Can't see the pane? Press F7)
    [VBA]Option Explicit
    Private Sub Document_Open()
    DoMailMerge
    End Sub
    Public Sub DoMailMerge()
    Dim DocName$
    DocName = ActiveDocument.Name
    'Do mailmerge
    With ActiveDocument.MailMerge
    .Destination = wdSendToNewDocument
    .Execute
    End With
    'Close mailmerge document
    Windows(DocName).Close wdDoNotSaveChanges
    End Sub

    [/VBA]
    • Now Close the editor and save the document.
    • Close this document and reopen it Choose yes when asked to activate Macro's
    • By now you should see a newly created document with the merge data in it.
    Btw..the code closes the mailmerge document after it has created a new merge document.

    That should be it with the information given.

    HTH,
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  3. #3
    Thank you - the security setting fixed the problem

    Go to Tools | Macro | Security
    Second Tab set securtiy to medium!! (Important)
    It works like a charm now.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Teresa,

    Excellent...you're welcome!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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