Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test if a file is password protected Nigel[_2_] Excel Programming 2 December 27th 07 03:24 PM
PASSWORD REMOVAL I have the password to open the file and the password to modify the file now how to remove them LJ[_4_] Excel Programming 0 April 27th 06 03:18 AM
Open Test file with VBA with a changing file number Michael from Austin Excel Programming 4 October 14th 05 03:18 PM
how to automate opening a password protected excel file? e.g. a .xls that has a password set in the security tab. Daniel Excel Worksheet Functions 0 June 23rd 05 11:56 PM
bypass password when update linking of password protected file Yan Excel Discussion (Misc queries) 1 February 7th 05 11:29 PM


All times are GMT +1. The time now is 09:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"