opening password protected workbook with viusal basic


Posted by n bruckerhoff on July 26, 2001 6:12 AM

I have a visual basic program that opens an excel 97 workbook and reads data from worksheets into various arrays. I need to protect the workbook so that my user cannot see the data/sheets in my workbook. After I have password protected the workbook, how can I open this workbook in my visual basic code. I'm assuming I need to pass the password, but I don't know how. If you have any advise - that would be great!
Thanks

Posted by Bob on July 26, 2001 7:58 AM

For some password code see Travis's response to Andre dated 7/25/01. Note that if you don't protect your macro code, the password is out there for all to see.

You may also want to turn off screen updating while you are doing this so the user doesn't see what is going on behind the scenes. Use these statements:

Application.ScreenUpdating = False
(your code here)
Application.ScreenUpdating = True



Posted by nicole on July 26, 2001 10:13 AM

The Excel sheets only contain data- no macros, so there's not a worry of that. The only concern of mine is whether the user can open the excel file and see the data, my VB project needs to read in the data. Here is the example of the DAO call from my visual baisc project.

DBEngine.OpenDatabase(DataBaseFile, False, True, "Excel 8.0;")

when I try passing the password I have tried

DBEngine.OpenDatabase(DataBaseFile, False, True, "Excel 8.0;pwd=mypassword"), the VB error that I get is 3161, cannot decrypt the file. do you see anything wrong with my vb code ?