How to check for password in an excel file.
Hi,
I would like to know how I can check whether an excel file is password protected or not. Thanks, Aatash |
How to check for password in an excel file.
Hi Aatash,
Aatash wrote: I would like to know how I can check whether an excel file is password protected or not. I'm not sure if you can determine that without attempting to open the file. If you specify a password when opening a workbook, that password will be ignored if the workbook is not password-protected. If the workbook is password-protected and the password you supply is incorrect, you'll get a 1004 runtime error, which you can trap: Sub test() On Error GoTo ErrHandler Workbooks.Open Filename:="c:\book1.xls", Password:="$$$$" ExitRoutine: Exit Sub ErrHandler: If Err.Number = 1004 And InStr(1, Err.Description, _ "Password", vbTextCompare) Then MsgBox "Password-protected workbook. Unable to open.", _ vbExclamation, "Error" Else MsgBox CStr(Err.Number) & ": " & Err.Description End If Resume ExitRoutine End Sub -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
All times are GMT +1. The time now is 05:32 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com