Error Trapping Web Queries in VBA

Terry_Orange

Board Regular
Joined
Jul 22, 2002
Messages
133
Hi folks,

I have a web query set up in Excel (below). It works fine unless the webpage does not exist. Any ideas anyone how I can go about error trapping this ?

THANK YOU
TO.



Code:
Sub ImportWebpage(ByVal PathName As String, ByVal PathNo As Integer)

    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.the_website_I'm_accessing" & PathName & "file.asp", _
        Destination:=Range("A1"))
        .Name = PathName & "file"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .Refresh BackgroundQuery:=False
    End With

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You're correct it does - at that line.

Thanks. Now I can go web-trawling for information ! I'm always surprised at how much more excel can actually do !

THANK YOU AGAIN.
TO
 
Upvote 0
I know this is an old post, but I searched this forum and I'm having a similar problem.

When my webquery reports the same error (though I think it's a message of some sort, not an error, because if I click okay, the macro/ontime timer resumes.)

However, I can't seem to trap the error at all, since it doesn't seem to be occurring on any particular line or procedure.
 
Upvote 0
I did some experimenting

The error can only be trapped this way if backgroundrefresh=false

if backgroundrefresh=true, putting on on error in the procedure does not help.

Any ideas how to get around this? I'd prefer the refresh be done in the background.
 
Upvote 0

Forum statistics

Threads
1,214,894
Messages
6,122,124
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top