Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default On Error Not Working...

I have some macros that go down a list of stock symbols, grab historical data
from Yahoo!, and then graph the data. The macros work well, but there's one
glitch. To test the code, I put a bogus stock symbol in (FMA - doesn't
exist). I have an "On Error Goto" statement just before the web query, and
when I try to query this symbol, the error trips and sends the macro to the
recovery code.

However, when I put two bad symbols in the list, the first one still trips
the "On Error", but the second one doesn't - instead the VBA debugger gives
me a run time error '1004' message: "The Internet site reports that the item
you requested could not be found. (HTTP/1.0 404)"

I can't figure out why the error trapping doesn't work the second time
around. The bogus stock symbols can be next to each other, or separated by
other "good" symbols, and the second one still doesn't work. Any ideas?

Thanks,

Eric

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default On Error Not Working...

The "Goto" in an On Error statement works differently than a normal
Goto. If there is a On Error Goto <label statement in effect and an
error occurs, VBA is running in "error mode" and On Error will not
handle any other errors. You have to get VBA out of "error mode" and
back into "normal mode". You do this with a Resume or Resume Next
statement (or by exiting the procedure). Thus your code would look
something like

Sub AAA()

On Error GoTo ErrHandler
'
' code that raises an error
'
ResumePoint:
'
' more code
'
Exit Sub
ErrHandler:
' handle the error
Resume Next
' or
Resume ResumePoint

End Sub

In the error handler block (the code between ErrHandler and End Sub),
you cannot have any error handling and you can't use Goto. Use Resume
instead.

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
The San Diego Project Group, LLC
(email is on the web site)
USA Central Daylight Time (-5:00 GMT)



On Tue, 30 Sep 2008 11:51:01 -0700, egun
wrote:

I have some macros that go down a list of stock symbols, grab historical data
from Yahoo!, and then graph the data. The macros work well, but there's one
glitch. To test the code, I put a bogus stock symbol in (FMA - doesn't
exist). I have an "On Error Goto" statement just before the web query, and
when I try to query this symbol, the error trips and sends the macro to the
recovery code.

However, when I put two bad symbols in the list, the first one still trips
the "On Error", but the second one doesn't - instead the VBA debugger gives
me a run time error '1004' message: "The Internet site reports that the item
you requested could not be found. (HTTP/1.0 404)"

I can't figure out why the error trapping doesn't work the second time
around. The bogus stock symbols can be next to each other, or separated by
other "good" symbols, and the second one still doesn't work. Any ideas?

Thanks,

Eric

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 on Working Macro cschultz25 Excel Discussion (Misc queries) 0 February 11th 11 07:20 PM
On error resume next not working cluckers Excel Discussion (Misc queries) 3 November 25th 09 08:12 PM
Error Trap not working OssieMac Excel Programming 4 April 2nd 08 01:55 PM
Error Handler Not Working Bill Excel Discussion (Misc queries) 0 August 25th 05 07:13 PM
error 50290 when working from dll PM Excel Programming 0 November 18th 04 10:05 AM


All times are GMT +1. The time now is 06:54 AM.

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"