How to Fix ADO Insert Errors Between Excel Workbooks
Question details
An Excel VBA procedure using ADO fails to insert data from a closed XLSX workbook into a separate XLSM workbook at the cn.Execute line.

- Product
- Microsoft Excel
- Device & OS
- Windows
- Scenario
- Copying data from a closed source Excel workbook into a macro-enabled destination workbook using VBA and ADO.
- Observed behavior
- The VBA macro throws a runtime error and fails exactly on the cn.Execute line during the SQL insert operation.
Ensure you have created a backup of your destination macro-enabled workbook (XLSM) and verify that the exact file paths referenced in your VBA code are completely accurate.
Verify the ADO Connection String and SQL Statement
Check the ACE OLEDB provider, connection properties, and the syntax of your SQL query to ensure accurate communication with the closed workbook.
ADO requires highly specific syntax and proper driver declarations to successfully query modern Excel formats (.xlsx and .xlsm). A minor typo in the connection string or the SQL statement will cause the cn.Execute command to fail.
Ensure your connection string uses 'Provider=Microsoft.ACE.OLEDB.12.0;' (or 16.0) instead of the outdated Jet provider, which does not support modern Excel formats.
Set the Extended Properties within the connection string to 'Excel 12.0 Xml;HDR=YES;' for proper handling of XLSX and XLSM files.
In your SQL statement, wrap the worksheet or table name in square brackets and append a dollar sign, such as `SELECT * FROM [Sheet1$]`.
Double-check that the file path to the closed XLSX source workbook is fully qualified and that the file is not currently moved or renamed.

Install the Required ACE OLEDB Provider
Ensure that the Microsoft Access Database Engine, which provides the necessary drivers for ADO to read Excel files, is correctly installed on your machine.
Perform a Clean Boot to Isolate Service Conflicts
Identify conflicting background services that might interfere with OLEDB drivers or lock file processing by performing a clean boot in Windows.
Try WPS Office for Seamless Data Management
If you frequently encounter complex VBA and driver errors in Microsoft Excel, consider switching to WPS Office. It provides robust spreadsheet capabilities, high compatibility with Excel formats, and built-in tools for easy data management without writing complex ADO connection code.
- 1. Download and Install: Visit the official WPS Office website to download the free installation package for your operating system.
- 2. Open Your Spreadsheets: Launch WPS Spreadsheets and open your existing .xlsx or .xlsm files directly without needing any conversion.
- 3. Manage Data Smoothly: Use built-in data import and export tools to move data between workbooks efficiently.

Frequently Asked Questions
Why does ADO fail on cn.Execute when querying an Excel file?
This typically happens due to incorrect worksheet naming in the SQL string (missing the $ symbol or square brackets), an invalid file path, or an improperly configured ACE OLEDB connection string.
Do I need to install special drivers to use ADO with XLSX files?
Yes, you must have the Microsoft Access Database Engine (ACE OLEDB provider) installed on your system to query modern Excel (.xlsx or .xlsm) files via ADO.
Can I query a closed Excel workbook without using ADO?
Yes, you can use Power Query (Get & Transform Data) to extract and manipulate data from a closed workbook, which is often more stable and doesn't require VBA code.




