Excel VBA Mail Merge to Word: Setup, Code, and Tips

VBA & macros · Updated November 3, 2026

Excel VBA Mail Merge to Word: Setup, Code, and Tips

Yes. In Excel for Microsoft 365 on Windows, VBA can open a Word mail-merge template connected to an Excel list, run the merge, and save the resulting document. The practical setup is to connect the list and insert merge fields in Word once, save that template beside the workbook, then run a short Excel macro whenever you need a fresh batch.

How an Excel-to-Word mail merge works

Excel stores the records, Word controls the layout, and Word’s Mail Merge feature combines them. A row in Excel typically represents one recipient; column headings such as FirstName, Address, and DueDate become fields that Word can insert into a letter, label, envelope, or other supported merge document.

VBA can automate Word from Excel. In the example below, the Word template already has its Excel data source selected and its merge fields in place. The macro opens the template, tells Word to send the merge to a new document, runs it, and saves the combined result as a new .docx file. It does not build the letter layout or choose recipients for you: those are configured in Word first.

This approach suits repeatable jobs such as monthly notices or batches of personalized letters. It is different from copying cells into Word one at a time, and it does not mean that Excel itself has a built-in Word mail-merge command. The merge engine and document formatting are Word features.

Prepare the Excel recipient list

Make the first row of the source list a row of unique, descriptive column headings. Put one recipient or record on each following row, and keep each type of information in its own column. For example, a simple worksheet named Contacts might look like this:

  • FirstName | LastName | Address | City | PostalCode | DueDate
  • Maya | Chen | 14 Oak Street | Albany | 01234 | 11/15/2026
  • Omar | Patel | 8 Pine Road | Albany | 12007 | 11/20/2026

Keep the records together in a clean rectangular range. Avoid merged cells, blank heading cells, and completely blank rows in the middle of the data. If the workbook contains several worksheets or tables, make a note of the exact worksheet or table that Word should use. Save the workbook before running the merge so Word reads the latest values.

Pay particular attention to dates, postal codes, and other values whose display matters. Excel may store a postal code such as 01234 as the number 1234, which loses the leading zero; set that column to Text before entering or importing the values, or use an appropriate Word field format. Formula cells can also produce values Word reads differently from the way they appear in Excel. Preview representative records before sending a batch.

Build and connect the Word template

In Word for Microsoft 365 on Windows, open a new document or an existing letter. Use Mailings > Start Mail Merge and choose the document type, such as Letters. Then choose Mailings > Select Recipients > Use an Existing List, browse to the Excel workbook, and select the Contacts worksheet or the relevant table in the workbook-selection dialog. If Word asks which range to use, choose the one containing the headings and records.

Place the cursor where each personalized value belongs and select Mailings > Insert Merge Field to insert fields such as FirstName or Address. For example, a letter could start with “Dear ” followed by the FirstName merge field. Use Mailings > Preview Results to inspect different recipients, and save the document as LetterTemplate.docx in the same folder as the Excel workbook. The saved template should remain the main merge document, not a previously merged batch.

Before automating, test the template manually with Mailings > Finish & Merge > Edit Individual Documents. This checks that Word can read the source and that the fields resolve as expected. The VBA code relies on this connection being saved with the template; if the workbook is moved or renamed, Word may prompt for the data source again.

Run the merge from Excel VBA

Save a copy of the workbook before running a macro. VBA actions cannot be undone with Ctrl+Z. With the workbook and LetterTemplate.docx in the same folder, press Alt+F11 in Excel for Windows, choose Insert > Module in the Visual Basic Editor, and paste in the code below. Change the template filename or output naming if your files use different names.

Sub RunWordMailMerge()
    Dim wordApp As Object
    Dim wordDoc As Object
    Dim mergedDoc As Object
    Dim templatePath As String
    Dim outputPath As String

    On Error GoTo Failed

    If Len(ThisWorkbook.Path) = 0 Then
        MsgBox "Save the Excel workbook before running the merge."
        Exit Sub
    End If

    ' Save current worksheet values before Word reads the source.
    ThisWorkbook.Save
    templatePath = ThisWorkbook.Path & Application.PathSeparator & _
                   "LetterTemplate.docx"
    outputPath = ThisWorkbook.Path & Application.PathSeparator & _
                 "Merged_" & Format(Now, "yyyymmdd_hhnnss") & ".docx"

    If Dir(templatePath) = "" Then
        MsgBox "Template not found: " & templatePath
        Exit Sub
    End If

    ' Late binding avoids needing to set a Word reference in VBA.
    Set wordApp = CreateObject("Word.Application")
    wordApp.Visible = True
    Set wordDoc = wordApp.Documents.Open(templatePath)

    With wordDoc.MailMerge
        .Destination = 0  ' 0 is Word's new-document destination.
        .SuppressBlankLines = True
        .Execute False     ' False means do not pause before merging.
    End With

    Set mergedDoc = wordApp.ActiveDocument
    mergedDoc.SaveAs2 outputPath, 16  ' 16 is the .docx document format.
    MsgBox "Merge complete: " & outputPath
    Exit Sub

Failed:
    MsgBox "Mail merge stopped: " & Err.Description
End Sub

The macro uses late binding: the variables that represent Word documents are declared as Object, and CreateObject starts Word. This avoids selecting a Microsoft Word Object Library reference in the VBA editor. The numeric values are Word constants: 0 directs the merge to a new document, and 16 saves in the default modern Word document format. The timestamp in the output filename gives each run a different filename rather than silently replacing the last batch.

To run it, return to Excel and press Alt+F8, select RunWordMailMerge, and choose Run. On a Mac, Option+F8 is commonly used to open the Macro dialog, though keyboard behavior can depend on the keyboard and macOS settings. This code is specifically for Windows: it uses Word’s COM automation through CreateObject and is not a drop-in Mac solution. Excel for the web does not run VBA macros.

Check the merged document and field formatting

Word opens visibly in this example so you can see whether the template loads and the merge completes. The generated document is saved in the workbook’s folder with a name such as Merged_20261103_143015.docx. Review it before distribution, especially the first and last records, long names, missing fields, and page breaks. A successful macro run confirms that Word produced a document; it does not confirm that every value or recipient is correct.

Word field formatting can help control presentation. For example, a date merge field can use a date switch such as { MERGEFIELD DueDate \@ "MMMM d, yyyy" } to display a date in a reader-friendly style. Word field braces are special; insert the merge field through the Word ribbon and edit its field code rather than typing ordinary braces as if they were field delimiters. For postal codes or account-like identifiers, preserving the source value as text is often safer than relying on automatic number formatting.

Common problems and practical fixes

  • Word asks for the source again: The template may not have been saved after selecting the Excel list, or the source workbook’s path changed. Reconnect it using Mailings > Select Recipients > Use an Existing List, test the merge, and save the template.
  • The macro says the template is missing: Confirm the workbook and LetterTemplate.docx are in the same folder and that the filename matches exactly. If not, change the templatePath assignment in the macro.
  • Fields appear blank or the wrong sheet is used: Check that the selected worksheet has headings in its first row and records beneath them. Re-select the correct worksheet or table in Word and preview several records.
  • Dates or zeros look wrong: Inspect the underlying Excel values and column types, not just their on-screen appearance. Preserve leading-zero identifiers as text and format dates in Word when the merged display needs a particular style.
  • Word does not start or automation is blocked: Confirm that desktop Word is installed and available. Macro security, organizational policy, or a protected file location can prevent code from running; do not lower security settings indiscriminately.
  • The output is incomplete: Look for blank records, unexpected filters, and merge conditions in Word. Run a manual merge to a new document and compare its record count with the source list.

If an error occurs, the macro displays the error description but deliberately does not close Word automatically. This leaves the open application available for inspection. Close any partially opened documents yourself after noting the problem, and avoid distributing an output file until its contents have been checked.

Windows, Mac, and non-VBA alternatives

The example targets desktop Excel and Word for Microsoft 365 on Windows. Mac versions of Office have VBA, but this particular automation method depends on Windows COM and the Word.Application automation object. It should not be expected to run unchanged on Mac; use Word’s mail-merge interface there, or develop and validate a Mac-specific automation approach for the installed Office version. Excel for the web cannot run VBA, although a workbook can be opened in the desktop app to run the macro.

If you only need a one-time batch, Word’s manual mail-merge commands may be simpler than maintaining VBA. For recurring workflows managed by an organization, Microsoft Power Automate or another approved document-generation system may be worth evaluating, but available connectors and licensing depend on the organization’s Microsoft 365 plan and configuration. For a modest, local batch, the saved Word template plus Excel macro is often enough; it keeps layout work in Word and repeatable launch steps in Excel.

Security and file-handling considerations

A mail merge can expose personal information by placing recipient details into many pages, so store the workbook and merged output only in locations authorized for that data. Check the recipient list and the final document before sharing it, and remove temporary output when it is no longer needed under your organization’s retention rules. The macro creates a new document; it does not email or print it.

Only run VBA from a workbook you trust. If Excel displays a security warning, follow your organization’s policy rather than enabling all macros globally. Keep an unmodified backup of the source workbook and template, since the merge may use saved workbook contents and macro operations cannot be reversed through Excel’s Undo command.

Frequently Asked Questions

Can Excel VBA create a Word mail merge?
Yes. Excel VBA can automate desktop Word on Windows, including running a mail merge. The template must be connected to the Excel data source, and Word must be installed.

Do I need to put the VBA code in Word?
No. In this method, the macro is stored in Excel and starts Word. You can also write automation in Word, but that is a different setup.

Can the macro connect to the Excel worksheet by itself?
The sample assumes the Word template already has the workbook and worksheet selected as its mail-merge data source. Connecting or changing a source entirely in code requires additional Word automation and depends on the workbook path and data range.

Can I run this macro on a Mac or in Excel online?
Not as written. It uses Windows COM automation, and Excel for the web does not run VBA. Use Word’s manual merge tools on Mac or run the macro in desktop Excel on Windows.

Does the macro send the merged letters by email?
No. It saves a merged Word document. Sending personalized email is a separate mail-merge destination or automation task and needs additional setup and review.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.