How to check for password in an excel file.

  • Thread starter Thread starter Aatash
  • Start date Start date
A

Aatash

Hi,

I would like to know how I can check whether an excel file
is password protected or not.

Thanks,
Aatash
 
Hi Aatash,
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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top