How to Use Excel VBA to Update Word Mail Merge Labels
Question details
The user needs to dynamically update Word mail merge labels using Excel VBA, but the labels fail to reflect new data records when the script runs.

- Product
- Microsoft Word and Excel
- Device & OS
- not provided
- Scenario
- Automating the creation and updating of a mail merge label document directly from an Excel data source using VBA scripts.
- Observed behavior
- Excel VBA successfully opens the Word label document and connects to the data source, but the mail merge labels do not update with the new records.
Ensure that both your Excel data source workbook and the target Word label document are saved locally in a trusted directory, and that macro execution is enabled in your Excel Trust Center settings.
Use the Word MailMerge Object Model in Excel VBA
Utilize Word's native MailMerge object model instead of relying on basic macro recordings or SendKeys to ensure the data source is properly refreshed and merged.
When automating mail merges between Excel and Word, basic recorded macros often fail to refresh the data connection. By scripting directly against the Word MailMerge object model, you can explicitly force Word to fetch the latest records from your Excel file using the OpenDataSource method.
Press Alt + F11 in Excel to open the Visual Basic for Applications (VBA) editor.
In the VBA editor, go to the top menu and click Tools > References. Scroll down the list, check 'Microsoft Word Object Library', and click OK. This allows your Excel macro to command Word.
Insert a new module (Insert > Module) and declare your Word Application and Document objects. Use the 'MailMerge.OpenDataSource' method in your script to point directly to your Excel file path and specify the SQL statement for the desired worksheet.
Add the 'MailMerge.Execute' command to generate the final merged document. Follow this with a command to save the resulting document to your preferred folder path.

Create Mail Merge Labels Easily with WPS Office
If complex VBA scripting isn't for you, WPS Office offers a highly intuitive, built-in Mail Merge feature that seamlessly connects spreadsheets to text documents without requiring a single line of code. It's a lightweight and highly compatible alternative to Microsoft Office.

Frequently Asked Questions
Why aren't my Word mail merge labels updating with new Excel data?
This usually happens if the Word document doesn't explicitly refresh its data connection upon opening. Using the OpenDataSource method in VBA forces Word to re-establish the link and fetch the latest records from your Excel file.
Can I run a mail merge entirely from Excel without opening Word?
Word must be opened in the background because the MailMerge engine belongs to Word, not Excel. You can hide the Word application window during the process by setting the Word.Application.Visible property to False in your VBA script.
How do I avoid the SQL security prompt when opening a mail merge document via VBA?
The SQL security warning can interrupt VBA execution. You can suppress it by temporarily disabling application alerts using 'Application.DisplayAlerts = False' in your script before opening the document, or by modifying the SQLSecurityCheck registry key for Word.
What is the OpenDataSource method in VBA?
OpenDataSource is a method of the Word MailMerge object that allows you to programmatically attach a data source, such as an Excel workbook, to a Word document and specify the exact sheet or data table to pull records from.




