Word 2003 Mail Merge Automation Issue RRS feed

  • Question

  • I am attempting to automate a mail merge in Word 2003 using VBScript.  I have created a main document for the merge and when I click Merge to New Document I get a new document called Envelopes1 with the correct number of envelopes and the correct address block data.  When I execute the VBScript below, I get a new document with the correct number of envelopes, but the address block data is not there.  The main document and the VBScript use the same datasource file, so I do not think it is a matter of the datasource file contents/format changing.  I have been executing this code in VBSEdit and DTS with the same results.  (I know this is old technology, but it is what I am stuck with right now.)

    I've been beating my head against this for 2 days.  Any ideas?

    Here's the code:

        Dim WordFileTemplateName
        Dim WordFileOutputName
        Dim appword
        Dim strDataSourceName

        strDataSourceName = "\\Endeavor\Public\ZInspectionOrders\SOI\SOIMailMergeDocs\SOI_5yrInsp_201101_MailList.csv"
        'DTSGlobalVariables("ExportBackup").Value & "SOI\SOIMailMergeDocs\" & DTSGlobalVariables("FileName").Value & "_MailList.csv" 
        WordFileTemplateName = "\\Endeavor\Public\ZInspectionOrders\Template\SOIMailMergeTemplate.doc"
        WordFileOutputName = "\\Endeavor\Public\ZInspectionOrders\SOI\SOIMailMergeDocs\SOIMailMerge_" _
                            & Year(Now()) & Right("00" & Month(Now()),2) & Right("00" & Day(Now()),2) & ".doc"

        Set appword = CreateObject("word.application")
        appword.Visible = True
        appword.DisplayAlerts = 0
        appword.Documents.Open WordFileTemplateName

        With appword.ActiveDocument.MailMerge
            .MainDocumentType = 2
            .Destination = 0
            .OpenDataSource strDataSourceName,5,False,False,True,,,,,,,,,,,0
            '.MailAsAttachment = False
            '.MailAddressFieldName = ""
            '.MailSubject = ""
            .SuppressBlankLines = True
            .Execute Pause=True

        With  appword.ActiveDocument

        appword.Quit (False) 'without saving
        set appword = nothing

    Thursday, March 17, 2011 8:20 PM


  • Hi Rick,

    I posted a reply yesterday, but it seems to have disappeared! My reply was along the lines of:

    What happens if you execute the mailmerge manually? Do the envelopes appear with the correct data?

    FWIW, you can replace:
    Year(Now()) & Right("00" & Month(Now()),2) & Right("00" & Day(Now()),2)
    Format(Now(), "YYYYMMDD")


    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by Harry Yuan Wednesday, March 23, 2011 3:35 AM
    Sunday, March 20, 2011 9:24 PM