VBA & Macro Problems

Fix Excel VBA ADO Error: Database or Object Is Read-Only

Kushani NimanthikaKushani Nimanthika Oct 19, 2026 869 views

Question details

The user encounters a 'Database or object is read-only' error when trying to open a workbook from a local hard drive using an ADO connection in an Excel VBA macro.

Fixing the Excel VBA ADO 'Database or Object Is Read-Only' Error
Product
Microsoft Excel 365
Device & OS
not provided
Scenario
Running a VBA macro to execute an ADO connection to a local Excel workbook.
Observed behavior
The macro throws a read-only error when accessing files from a local drive, despite the exact same code successfully connecting when the file is stored on a USB drive.
Before you start

Ensure that the target Excel workbook is fully closed and not currently locked by another background process, user, or active Protected View window.

Solution 1Recommended

Update to the ACE OLEDB Provider

Mixing older Jet providers with modern Excel files can cause read-only errors. Standardizing to the Microsoft ACE provider resolves connection and architecture mismatches.

The Microsoft.Jet.OLEDB.4.0 provider is an older 32-bit driver designed for legacy formats (.xls). For modern Excel 365 environments and .xlsx/.xlsm files, you must consistently use the ACE OLEDB provider.

1
Open the VBA Editor

Press ALT + F11 in Excel to open the VBA Editor and locate your ADO connection script.

2
Replace the Provider String

Change your connection code from Provider=Microsoft.Jet.OLEDB.4.0 to the modern equivalent: Provider=Microsoft.ACE.OLEDB.12.0;.

3
Update the Data Source Properties

Ensure your connection string includes the correct extended properties for modern Excel files, formatted as: Extended Properties="Excel 12.0 Xml;HDR=YES;IMEX=0";.

4
Set an Explicit File Path

In your code, avoid using ActiveWorkbook as it may reference the wrong file if multiple windows are open. Instead, use ThisWorkbook.FullName to strictly target the workbook executing the macro.

Update to the ACE OLEDB Provider
Architecture Match: Ensure the installed Microsoft Access Database Engine (ACE provider) matches your Office installation architecture (either 32-bit or 64-bit).
Free Microsoft Office alternative

Upgrade Your Productivity with WPS Office

Troubleshooting deep VBA and ADO errors in Microsoft Office can be highly time-consuming. Consider WPS Office as a lightweight, fast, and completely free alternative that seamlessly supports Microsoft Excel formats, ensuring your workflows remain uninterrupted.

Free and lightweight software suiteHigh compatibility with Microsoft Excel formats (.xlsx, .xlsm)Familiar and intuitive user interfaceSeamless migration of your existing spreadsheets and documents
microsoft office alternative - wps office

Frequently Asked Questions

Why does my ADO code work perfectly on a USB drive but fail on my local drive?

This commonly happens because USB drives (often formatted as FAT32 or exFAT) have less restrictive security permissions compared to a local NTFS drive. Folder security settings, user permissions, or active OneDrive synchronization on your local drive may lock the file or restrict ADO's write access.

What is the difference between the Jet.OLEDB and ACE.OLEDB providers?

Microsoft.Jet.OLEDB is a legacy 32-bit provider designed for older Excel formats (.xls). Microsoft.ACE.OLEDB is the modern engine required to connect to current Excel formats (.xlsx, .xlsm) and supports both 32-bit and 64-bit Office environments.

How can I avoid locking the workbook when using ADO?

To prevent locking issues, ensure that the workbook isn't opened in Protected View. Always define your ADO connections strictly to close immediately after the query executes, and avoid updating open worksheets using ADO if Excel is simultaneously writing to them.

How do I correctly reference my current workbook path in ADO?

Avoid using ActiveWorkbook.FullName, as it can lead to errors if the user clicks a different open workbook while the macro runs. Instead, use ThisWorkbook.FullName to explicitly reference the exact workbook where your VBA code resides.