Is .xls password protected.

  • Thread starter Thread starter Tim Marsden
  • Start date Start date
T

Tim Marsden

Hi,

How do I tell if a .xls file has a password before I try and open it. I
don't mean a Workbook password but a file password.
The one applied when you do a save as.

Tim
 
Try to open it and handle the error

On Error Resume Next
set kb = Workbooks.Open("C:\MyFiles\Myfile.xls")
On Error goto 0
if kb is nothing then
msgbox "Has password"
exit sub
End if
 
Thanks for the reply

I am using vb.net interop, If I try and open a workbook using
XL.Workbooks.Open("ABC.xls") without supplying a password, it prompts me for
one,.
I have DisplayAlerts = False set.

Tim
 
This is tested and works in Excel:

Sub AAATEst()
Dim wkbk As Workbook
On Error Resume Next
Set wkbk = Workbooks.Open("C:\Data6\AAABook.xls", _
Password:="", WriteResPassword:="")
On Error GoTo 0
If wkbk Is Nothing Then
MsgBox "Has Password"
End If
End Sub

It will open a workbook that is not password protected.

don't know if it will work for .Net.
 
Just replace "C:\Data6\AAABooks.xls" with a variable

How you populate that variable would be different in .Net than I would od it
in Excel VBA.
 
Thanks for your code Tom,
Works beautifully...
It will be even more useful if you can modify your code so that the target
file can be searched and selected from any windows directory.
Or am I asking too much?
Regards
 
Thank you for the info...

Tom Ogilvy said:
Just replace "C:\Data6\AAABooks.xls" with a variable

How you populate that variable would be different in .Net than I would od it
in Excel VBA.

--
Regards,
Tom Ogilvy

prompts
 

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