Almost same web query on every sheet

JVD

New Member
Joined
Mar 24, 2013
Messages
11
I want to launch almost the same web query on every sheet. The only thing that changes is a little thing in the webadres (=parameter). These parameters are in the A1 cel of each sheet.
Is it possible to do this automatically?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Build up a hyperlink by concatenation. Try the following as an example:
in B1: =HYPERLINK("http://" &A1&".com")
in A1: "www.google"

now click on the link in B1
 
Upvote 0
Yes, but I now it just opens the webpage?
I want that the webquery would be launched on every sheet, but for each sheet a different parameter (which is standing in cel A1)
 
Upvote 0
Sorry, my mistake. I misinterpreted as wanting to send a query formatted http request.
You can do it with VBA. The example below has the entire query URL in A1 but you can just as easily concatenate one. You can call the macro from each worksheet_activate event and it will select the ranges in the activesheet and refresh the data whenever you select a different sheet tab.

Code:
Sub Web_Query()
   With ActiveSheet.QueryTables.Add(Connection:= _
      "URL;" & Range("A1"), _
         Destination:=Range("B1"))
      .BackgroundQuery = True
      .TablesOnlyFromHTML = True
      .Refresh BackgroundQuery:=False
      .SaveData = True
   End With
End Sub
 
Upvote 0
Thanks for your answer. Now I'm already a step forwards, but I just doesn't understand yet how I can make it to do it for every sheet automatically? But thank you already!
 
Upvote 0
This creates the web query posted by Teeroy on all sheets:
Code:
Sub Web_Query_All_Sheets()

    Dim ws As Worksheet
    Dim qt As QueryTable
    
    For Each ws In Worksheets
        With ws
            Set qt = .QueryTables.Add(Connection:="URL;" & .Range("A1").Value, Destination:=.Range("B1"))
            With qt
                .BackgroundQuery = True
                .TablesOnlyFromHTML = True
                .Refresh BackgroundQuery:=False
                .SaveData = True
            End With
        End With
    Next
    
End Sub
If that particular web query doesn't work or retrieves the wrong web data (it is missing several properties which specify exactly which data should be retrieved), do a manual web query with the macro recorder and incorporate the code generated into the With qt block of code above.
 
Upvote 0
Yes, that works indeed, but there is a little problem: when there is a wrong URL, it gives an ERROR and then it stops. The sheets after the one with the wrong URL aren't done anymore. Is there a way to say if there is a wrong URL or an ERROR, it don't have to stop, but just go one and still do the other sheets?
 
Upvote 0

Forum statistics

Threads
1,203,515
Messages
6,055,845
Members
444,828
Latest member
StaffordStag

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