T
Tim
Hi All-
I'm using Excel 2003 on Windows XP Pro. I've got some excel code that
loops through a selection of files, opening them one at a time, running
some code, then closing them. I'm running into a snag when I try to
open a file with a password, the code stops with a run-time error 1004.
If the file is password-protected, I don't want to open it, just skip
over it & go on to the next one. The problem is, my error handler isn't
working. Here's what I have:
Sub AAATEst()
Dim wkbk As Workbook, strFile as String
On Error GoTo Error_Handler
'Begin loop
strFile = "Whatever"
Set wkbk = Workbooks.Open(Filename:=strFile, _
Password:="", WriteResPassword:="")
'do some code here
'do some code here
ResumeHere:
'go to next file
Exit Sub
Error_Handler:
If Err.Number = 1004 Then
MsgBox "File has a password"
Err.Clear
GoTo ResumeHere
Else
MsgBox "Run-time error # " & Err.Number & Chr(13) &
Err.Description
Stop
End If
End Sub
the problem is that the error handler is not tripping when I try to
open the password-protected file. It's just coming up telling me that
the password is not correct. Is there any way to trap the incorrect
password error and just skip over that file?
Sorry if that's confusing, I tried to make it as clear as possible.
Thanks,
Tim
I'm using Excel 2003 on Windows XP Pro. I've got some excel code that
loops through a selection of files, opening them one at a time, running
some code, then closing them. I'm running into a snag when I try to
open a file with a password, the code stops with a run-time error 1004.
If the file is password-protected, I don't want to open it, just skip
over it & go on to the next one. The problem is, my error handler isn't
working. Here's what I have:
Sub AAATEst()
Dim wkbk As Workbook, strFile as String
On Error GoTo Error_Handler
'Begin loop
strFile = "Whatever"
Set wkbk = Workbooks.Open(Filename:=strFile, _
Password:="", WriteResPassword:="")
'do some code here
'do some code here
ResumeHere:
'go to next file
Exit Sub
Error_Handler:
If Err.Number = 1004 Then
MsgBox "File has a password"
Err.Clear
GoTo ResumeHere
Else
MsgBox "Run-time error # " & Err.Number & Chr(13) &
Err.Description
Stop
End If
End Sub
the problem is that the error handler is not tripping when I try to
open the password-protected file. It's just coming up telling me that
the password is not correct. Is there any way to trap the incorrect
password error and just skip over that file?
Sorry if that's confusing, I tried to make it as clear as possible.
Thanks,
Tim