PC Review


Reply
Thread Tools Rate Thread

Bypass Error Q

 
 
Sean
Guest
Posts: n/a
 
      16th Oct 2008
I have a simple piece of code below that refresh's some web queries to
get stock prices. What I have encountered is that sometimes a
particular query will return an error (web page not available etc),
what I wish to do, is if that happens, just bypass the particular
query and move to the next one.

How would I incorporate that in to be code?

Sub GetLatestPrices()

Application.ScreenUpdating = False
Sheets("Web Prices").Activate
ActiveSheet.Visible = True

Range("A3").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

Range("A14").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

Range("A25").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

Application.ScreenUpdating = True

End Sub
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      16th Oct 2008
You can ignore errors by using an On Error Resume Next statement. Note
that this does not by any measure *fix* an error; it merely ignores
the error and allows the code to continue running. The error may have
side effects. Generally, a blanket On Error Resume Next is dangerous
because it ignores all errors, not just a particular type of error,
but in the context of a small procedure like the one you illustrate,
it is probably fine to use on On Error Resume Next statement for the
entire procedure. E.g,

Sub GetLatestPrices()
On Error Resume Next
' your existing code goes here
End Sub

I have quite a bit of information about error handling at
http://www.cpearson.com/Excel/ErrorHandling.htm .


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Thu, 16 Oct 2008 09:18:46 -0700 (PDT), Sean
<(E-Mail Removed)> wrote:

>I have a simple piece of code below that refresh's some web queries to
>get stock prices. What I have encountered is that sometimes a
>particular query will return an error (web page not available etc),
>what I wish to do, is if that happens, just bypass the particular
>query and move to the next one.
>
>How would I incorporate that in to be code?
>
>Sub GetLatestPrices()
>
> Application.ScreenUpdating = False
> Sheets("Web Prices").Activate
> ActiveSheet.Visible = True
>
> Range("A3").Select
> Selection.QueryTable.Refresh BackgroundQuery:=False
>
> Range("A14").Select
> Selection.QueryTable.Refresh BackgroundQuery:=False
>
> Range("A25").Select
> Selection.QueryTable.Refresh BackgroundQuery:=False
>
> Application.ScreenUpdating = True
>
>End Sub

 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      17th Oct 2008
Thanks Chip

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bypass error message to debug Teddy Microsoft Excel Programming 5 8th Mar 2010 12:43 AM
How to bypass Microsoft Error Reporting. Control Freq Windows XP General 1 18th Mar 2008 04:14 PM
How to bypass Excel error message =?Utf-8?B?bWF0ZWxvdA==?= Microsoft Excel Programming 2 28th Aug 2006 06:48 AM
Bypass xp logon /error 0x80004005 Steve Windows XP General 1 10th Jun 2005 12:59 PM
Error Message bypass =?Utf-8?B?YmlnIGQ=?= Microsoft Access VBA Modules 2 18th Mar 2005 10:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:41 PM.