Data Import & Export

How to Fix ADO Insert Errors Between Excel Workbooks

Steve KSteve K Oct 26, 2026 868 views

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.

How to Fix ADO Insert Errors Between Excel Workbooks
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.
Before you start

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.

Solution 1Recommended

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.

1
Check the OLEDB Provider

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.

2
Verify Extended Properties

Set the Extended Properties within the connection string to 'Excel 12.0 Xml;HDR=YES;' for proper handling of XLSX and XLSM files.

3
Correct Worksheet Syntax

In your SQL statement, wrap the worksheet or table name in square brackets and append a dollar sign, such as `SELECT * FROM [Sheet1$]`.

4
Validate File Paths

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.

Verify the ADO Connection String and SQL Statement
Protected Sheets: If the source workbook contains password-protected sheets or is encrypted, ADO cannot read it. Ensure the file has no password-to-open restrictions.
Free Microsoft Office alternative

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. 1. Download and Install: Visit the official WPS Office website to download the free installation package for your operating system.
  2. 2. Open Your Spreadsheets: Launch WPS Spreadsheets and open your existing .xlsx or .xlsm files directly without needing any conversion.
  3. 3. Manage Data Smoothly: Use built-in data import and export tools to move data between workbooks efficiently.
Highly compatible with Microsoft Excel formats (.xlsx, .xlsm, .xls)Built-in support for advanced formulas and macros in the Pro versionLightweight application that runs smoothly on most operating systemsFree to use for everyday data management and reporting tasks
microsoft office alternative - wps office

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.