Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default On Error GoTo Failing - HELP!

I have this code in a loop that saves a series of file to handle the error
created when the path doesn't exist. The first time a file throws an error
the GoTo Newpath exicutes correctly. When a second file produces the same
error it ignores the "On Error GoTo NewPath" statement and displays the 1004
Run Time Error message. If I hit debug and back the code up to the on error
statement it still fails. Any idea why On Error isn't working after the
initial hit?
Thanks,
John

On Error GoTo NewPath
Workbooks(Wcount + 1).SaveAs Filename:=vPath & "\" & SaveName, _
FileFormat:=xlNormal, PassWord:=vPassword, WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

NewPath:
If Err < 0 Then
MsgBox ("No L drive path for " & vPath & " file " & SaveName & "
saved to 77xx")
Workbooks(Wcount + 1).SaveAs "L:\North America\77xx\" & SaveName
Err = 0
On Error GoTo 0
End If

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default On Error GoTo Failing - HELP!

in your module, type resume, highlight it and hit F1

Without seeing the whole context of the code snippet, I would say:
Your error handler hasn't terminated until you execute a resume statement.
So when you continue to process and hit the second error, it looks to excel
like you have hit an error in the error handler. In frustration, excel/vba
gives up - raising the white flag.

fix your error handler to use a resume statement and you should be good.

--
Regards,
Tom Ogilvy


"John Hutcins" wrote:

I have this code in a loop that saves a series of file to handle the error
created when the path doesn't exist. The first time a file throws an error
the GoTo Newpath exicutes correctly. When a second file produces the same
error it ignores the "On Error GoTo NewPath" statement and displays the 1004
Run Time Error message. If I hit debug and back the code up to the on error
statement it still fails. Any idea why On Error isn't working after the
initial hit?
Thanks,
John

On Error GoTo NewPath
Workbooks(Wcount + 1).SaveAs Filename:=vPath & "\" & SaveName, _
FileFormat:=xlNormal, PassWord:=vPassword, WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

NewPath:
If Err < 0 Then
MsgBox ("No L drive path for " & vPath & " file " & SaveName & "
saved to 77xx")
Workbooks(Wcount + 1).SaveAs "L:\North America\77xx\" & SaveName
Err = 0
On Error GoTo 0
End If

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default On Error GoTo Failing - HELP!

That was it! I added a Resume statement and it works fine.
Thanks for your help,
John

"Tom Ogilvy" wrote:

in your module, type resume, highlight it and hit F1

Without seeing the whole context of the code snippet, I would say:
Your error handler hasn't terminated until you execute a resume statement.
So when you continue to process and hit the second error, it looks to excel
like you have hit an error in the error handler. In frustration, excel/vba
gives up - raising the white flag.

fix your error handler to use a resume statement and you should be good.

--
Regards,
Tom Ogilvy


"John Hutcins" wrote:

I have this code in a loop that saves a series of file to handle the error
created when the path doesn't exist. The first time a file throws an error
the GoTo Newpath exicutes correctly. When a second file produces the same
error it ignores the "On Error GoTo NewPath" statement and displays the 1004
Run Time Error message. If I hit debug and back the code up to the on error
statement it still fails. Any idea why On Error isn't working after the
initial hit?
Thanks,
John

On Error GoTo NewPath
Workbooks(Wcount + 1).SaveAs Filename:=vPath & "\" & SaveName, _
FileFormat:=xlNormal, PassWord:=vPassword, WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

NewPath:
If Err < 0 Then
MsgBox ("No L drive path for " & vPath & " file " & SaveName & "
saved to 77xx")
Workbooks(Wcount + 1).SaveAs "L:\North America\77xx\" & SaveName
Err = 0
On Error GoTo 0
End If

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
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
All macros failing part way through with different error messages magpie Excel Discussion (Misc queries) 2 March 24th 05 02:31 PM
all macros failing - different workbooks different error messages. magpie Excel Discussion (Misc queries) 1 March 23rd 05 03:10 PM
On Error Goto doesn't goto Paul Excel Programming 1 October 15th 04 03:51 PM
On Error Goto doesn't goto Paul Excel Programming 0 October 15th 04 03:05 PM


All times are GMT +1. The time now is 02:03 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"