Test if a file has a password

S

Steven

Is there code to test an unopened file to see if it has a password. I just
want it to return True or False or something like that, that the file is
password protected or not. And definitely I do not want to have to open the
file I am testing first.

Thank you,

Steven
 
J

JLGWhiz

I haven't tried it on an unopened workbook, you could possibly substitute the
workbook name for ActiveWorkbook and try it. Workbooks("FileName.xls")
format.

If ActiveWorkbook = True Then
MsgBox "File had Password"
Else
MsgBox "Not Password Protected"
End If
 
S

Steven

I think that will work. Thank you. The issue is since in code you can put
Workbooks.Open FileName:="aaaa.xls", Password:="whatever" and it will open
if the file does not have a password, which is unusual to me, then just test
the opened file from the original file to make sure it was password
protected, then that means the password had to match. If it opens and "No
Password" then just close the file without saving.

Thank you again,

Steven
 
J

JLGWhiz

I just tried it and as I suspected, it gives a Subscript Out of Range
message. So I would imagine that it would be simpler to just write the code
as you said to do a logical test when opening the file and handle it with
code.
 

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

Top