Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem with error trapping


I am writing a data compiling program that when run updates a master
sheet. I have files that have "_COMP" added to the end of the file
name if they have been updated. I am trying to open every file as if
it has the _COMP, but most do not, so an error is generated. I catch
the error no problem the first round, but on the next pass in a for
loop, it displays the error (from trying to open a file that doesnt
exist) rather than catching it. I have tried the error.clr call but
still no help. My code looks like this more or less:

For Each wsSheet In Worksheets
On Error GoTo notCOMP
Set wBook = Workbooks(wsSheet.name & "_COMP.xls")

If wBook Is Nothing Then 'Wkbk is NOT open
'Opens
Workbooks.Open Filename:="G:\ROHS\" & name & "\" &
wsSheet.name & "_COMP.xls"
On Error GoTo notCOMP
End If
........
<code
........
notCOMP:
<code
Err.Clear
Next wsSheet

Any ideas on why I cant clear out the error?


--
McManCSU
------------------------------------------------------------------------
McManCSU's Profile: http://www.excelforum.com/member.php...o&userid=24379
View this thread: http://www.excelforum.com/showthread...hreadid=389120

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problem with error trapping

You need a resume statement in your error handler. Until a resume statement
is executed, you are still in error handler mode and an error in the error
handler causes excel to halt.

In the module, type
Resume
highlight it and hit F1. This will explain it to you.

--
Regards,
Tom Ogilvy

"McManCSU" wrote in
message ...

I am writing a data compiling program that when run updates a master
sheet. I have files that have "_COMP" added to the end of the file
name if they have been updated. I am trying to open every file as if
it has the _COMP, but most do not, so an error is generated. I catch
the error no problem the first round, but on the next pass in a for
loop, it displays the error (from trying to open a file that doesnt
exist) rather than catching it. I have tried the error.clr call but
still no help. My code looks like this more or less:

For Each wsSheet In Worksheets
On Error GoTo notCOMP
Set wBook = Workbooks(wsSheet.name & "_COMP.xls")

If wBook Is Nothing Then 'Wkbk is NOT open
'Opens
Workbooks.Open Filename:="G:\ROHS\" & name & "\" &
wsSheet.name & "_COMP.xls"
On Error GoTo notCOMP
End If
.......
<code
.......
notCOMP:
<code
Err.Clear
Next wsSheet

Any ideas on why I cant clear out the error?


--
McManCSU
------------------------------------------------------------------------
McManCSU's Profile:

http://www.excelforum.com/member.php...o&userid=24379
View this thread: http://www.excelforum.com/showthread...hreadid=389120



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 Trapping gazza67[_2_] Excel Discussion (Misc queries) 2 September 6th 07 06:11 PM
Error Trapping from WSH Tom Chau Excel Discussion (Misc queries) 1 August 25th 06 04:21 AM
error trapping [email protected] Excel Programming 2 April 5th 05 12:52 AM
Error trapping Luis Excel Programming 1 November 11th 04 03:25 AM
Problem trapping an error Keith Excel Programming 0 May 21st 04 01:42 PM


All times are GMT +1. The time now is 06:45 PM.

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

About Us

"It's about Microsoft Excel"