What's the Connection String for Excel 2007 Macro enabled workbook when it is protected

I found the useful connection string to access to Excel 2007 Macro enabled workbook.

Here is the connection string

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\report.xlsm;Extended Properties='Excel 12.0 Macro;HDR=YES'

I am a .NET developer, I used OleDbConnection to access the workbook. It works when the workbook is not protected.

However, if the workbook is protected by a password, then it shows "External table is not in the expected format".

I tried to append the password to the string, then it becomes
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\report.xlsm;Extended Properties='Excel 12.0 Macro;HDR=YES';Password=112233

When the program runs, it displays the message "Cannot start your application. The workgroup information is missing or opened exclusively by another user."

Does anyone knows the connection string to Excel 2007 Macro enabled workbook when it is protected by a password?

Thanks,

1 answer

You have to open the workbook first if it is password protected. The password protects the workbook and not just the data. You can open it hidden to work in the background and close it after you are done with the data.