Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing To See If An Excel Workbook Is Protected

Status
Not open for further replies.

dtqbterror

Programmer
May 17, 2001
87
US
I have an application that opens a Excel Workbook and updates several cells. Sometime the Workbook will be Password Protected and sometimes it will not. I have searched all over the Internet to find a way to test to see if the Workbook is protected before opening it. This way I can prompt for the password. Does anyone know if there is a way to check this in C#?

Thanks.

 
Well, to my knowledge, there is not a way to open a password protected Excel file (at least using ADO.net). So I wouldn't be able to help you out there if you wanted to do that.

But if you are just looking to open unprotected files, and skip over protected ones, the best I could think of would be to open the file and do the updates in a try/catch block. I'm not sure what type of exception it throws, but catch for it and skip all the rest if it goes to the catch. Hopefully that helps a little.



Ron Wheeler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top