Fix Word Mail Merge OpenDataSource Select Table Prompt
Question details
Users encounter an unexpected Select Table dialog box when running a Word mail merge via a VBA macro connected to an Excel data source.

- Product
- Microsoft Word / Excel
- Device & OS
- not provided
- Scenario
- Automating a Word mail merge connected to an Excel data source with an SQL filter using VBA.
- Observed behavior
- Word displays a 'Select Table' dialog box and interrupts the macro instead of seamlessly executing the merge, typically due to incorrect SQL filter syntax or variable concatenation.
Ensure you have access to the VBA editor in your Word document and verify the exact names of your target Excel sheet and the variables used in your SQL query.
Correct the VBA Connection String and SQL Filter Syntax
Fix syntax errors and missing single quotation marks in your VBA code to prevent Word from losing the table reference and prompting the user.
When passing a text variable to an SQL query in VBA, the text value must be wrapped in single quotation marks. Additionally, the Excel file path variable needs proper concatenation within the connection string to be parsed correctly by the OpenDataSource method.
Press Alt + F11 to open your VBA editor and locate the module containing your MailMerge.OpenDataSource method.
Modify the connection string to concatenate the Excel file variable properly. Use: "Data Source=" & sDatFile & ";Mode=Read;Extended Properties=""HDR=YES;IMEX=1"";"
Ensure that your text filter value is enclosed in single quotes. Modify the SQL statement to look like this: sSql = "SELECT * FROM `Current$` WHERE `WEEK_START` = '" & strWeek & "'"
Save your VBA code and run the macro again to verify that the mail merge processes the Excel data source without triggering the Select Table dialog box.
Perform Seamless Mail Merges with WPS Writer
Avoid complex VBA coding and SQL syntax errors by using the intuitive Mail Merge wizard in WPS Writer to connect Excel data sources effortlessly.
- 1. Open WPS Writer: Open your main document template in WPS Writer and navigate to the 'References' tab on the top ribbon.
- 2. Connect the data source: Click 'Mail Merge' and select 'Open Data Source'. Browse your computer to locate and select your target Excel file.
- 3. Select specific records: Click 'Mail Merge Recipients' to visually check, uncheck, or filter the specific rows of data you want to include in the merge.
- 4. Insert fields and merge: Use the 'Insert Merge Field' button to place dynamic data into your document, then click 'Merge to New Document' to generate the final files.

Frequently Asked Questions
Why does Word keep asking me to select a table during Mail Merge?
This usually happens when Word cannot correctly parse the data source connection string or the SQL query via VBA. A missing single quote in a text filter or an improperly formatted sheet name causes Word to lose the data reference, forcing it to ask the user to manually select the correct table.
How do I format an Excel sheet name in a VBA SQL query?
When referencing an Excel worksheet in an SQL query string via VBA, you must append a dollar sign to the sheet name and wrap the entire string in backticks or brackets, for example: `SELECT * FROM \`Sheet1$\``.
Can I filter Mail Merge data without using VBA?
Yes. You can use the built-in 'Mail Merge Recipients' dialog box found in the Mailings (or References) tab. This feature allows you to visually filter, sort, and select specific records from your Excel data source without needing to write any VBA scripts or SQL code.




