web scraping on office 2021

Tonmoymridha

New Member
Joined
Nov 18, 2019
Messages
12
this code shows error 1004 on my office 2021 but its work fine on office 365 , can you help me out anyone?

VBA Code:
Function TEN_RACE_CREATION1()

    Dim url As String
    Dim table As QueryTable
    Dim ws As Worksheet
    Dim lastRow As Long
    
    Sheets("Meeting Results").Activate
    Sheets("Meeting Results").Columns("A:Q").Delete Shift:=xlToLeft
    Sheets("Meeting Results").Range("A1").Select
    url = "https://www.racingaustralia.horse/FreeFields/Results.aspx?Key=" & Sheets("Track_Tables").Range("G43").Value
    Set ws = Sheets("Meeting Results") ' Change the sheet reference as per your requirement
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
    
    Set table = ws.QueryTables.Add("URL;" & url, ws.Cells(lastRow, "A"))
    
    With table
        .WebSelectionType = xlAllTables ' Collect data from all tables on the web page
        .WebFormatting = xlWebFormattingRTF
        .Refresh
    End With
    
End Function
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
A couple of questions...
  1. Which line is causing the error?
  2. What value does G43 contain?
 
Upvote 0
When I run your macro with the full url address that you provided, it runs successfully without any errors.

What's the exact value that G43 contains?

Do you still get an error if you replace...

VBA Code:
url = "https://www.racingaustralia.horse/FreeFields/Results.aspx?Key=" & Sheets("Track_Tables").Range("G43").Value

with


VBA Code:
url = "https://www.racingaustralia.horse/FreeFields/Results.aspx?Key=2023Apr26,QLD,Toowoomba"

?
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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