excel ADO connection string

Hi All,
when attempting to read data from and encrypted xlsx using:
dbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & SourceFile & "';Extended Properties=Excel 12.0;"
and dbConnection.Execute.

I get an error:
Error -2147467259, External table is not in the expected format. occurred in GetRecordsetFromClosedWorkbook

The error goes away when the file is not encrypted.

adding ;Database Password =test; to the connection string gives a different error:

Error -2147467259, Could not find installable ISAM. occurred in GetRecordsetFromClosedWorkbook

When I use Excel Open (with password) and copy/paste methods all is good

How does one add Excel encryption password to the ADO connection string?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Password parameter does not help here but you may use the work around described here: http://www.connectionstrings.com/how-to-open-password-protected-excel-workbook/
You just have to change JET.OLEDB for ACE.OLEDB etc.

Another possibility is to save decrypted workbook into a temporary file and then open it via ADO.

Yes, Microsoft could do it better...
COACHMAN99Author Commented:
Hi pcelba
thanks for the input. Unfortunately there are thousands of workbooks in this situation and inputting passwords at a prompt isn't an option. (and when I use workbook.open with a password param, to read data, I am able to work without any prompts; just wanted to use ADO).
It is not necessary to ask user for the password but you may provide it as a parameter when opening the Excel workbook.

I don't know the exact syntax but you may use something like this:
Dim xl As New Excel.Application
Dim xwb As Excel.WorkBook

Set xwb = xl.Application.WorkBooks.Open "YourXLSXfile", , , , "password", "password"

and now you should be able to use ADODB connection without any restrictions.

I've tested FoxPro variant of above code and it opens password protected workbook without user intervention.
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

COACHMAN99Author Commented:
I wasn't asking a question; just informing you of how I currently work around the password issue. (Workbooks.Open("L:\Backup\2014\PGT\BE.xlsx", , , , "test")
Yes, my English is not so good... you wrote "just wanted to use ADO" which I translated as you cannot use ADO even after opening the workbook via OLE automation...
COACHMAN99Author Commented:
1. One cannot use a password in an ADO connection to an encrypted Excel workbook.
2. Instead, one must use the Excel 'workbook.open' functionality (which makes use of the optional password).

thanks pcelba for input.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
COACHMAN99Author Commented:
only workable option.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.