ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Test if a file has a password (https://www.excelbanter.com/excel-programming/413355-test-if-file-has-password.html)

steven

Test if a file has a password
 
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

JLGWhiz

Test if a file has a password
 
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


"Steven" wrote:

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


steven

Test if a file has a password
 
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

"JLGWhiz" wrote:

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


"Steven" wrote:

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


JLGWhiz

Test if a file has a password
 
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.

"Steven" wrote:

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

"JLGWhiz" wrote:

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


"Steven" wrote:

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



All times are GMT +1. The time now is 02:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com