Hi,
I have recorded a macro for a web query. Give all the information I need, however, I noticed that the url will always change. I have a cell N4 that I would like to copy and paste any URL I like to and the macro below use the link in that cell for the data to be scraped. I need to modify the below. I am not that great so any assistance would be great:
Sub Race1ImportData()
'
' Race1ImportData Macro
'
'
ActiveWorkbook.Queries.Add Name:="Table 2", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""thesimleague.com/events/atr-gt3-2023-h2/round-01""))," & Chr(13) & "" & Chr(10) & " Data2 = Source{2}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data2,{{""#"", type text}, {""Driver"", type text}, {""Car"", type text}, {""Grid position"", type text}, {""Laps"", Int64.Type}, {""Total time"", type text}, {""Avg.Lap"", type text}, {""Fa" & _
"stest sectors"", type text}, {""Optimal"", type text}, {""Fastest lap"", type text}, {""Tot.Points"", Int64.Type}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table 2"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Table 2]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_2"
.Refresh BackgroundQuery:=False
End With
End Sub
I have recorded a macro for a web query. Give all the information I need, however, I noticed that the url will always change. I have a cell N4 that I would like to copy and paste any URL I like to and the macro below use the link in that cell for the data to be scraped. I need to modify the below. I am not that great so any assistance would be great:
Sub Race1ImportData()
'
' Race1ImportData Macro
'
'
ActiveWorkbook.Queries.Add Name:="Table 2", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""thesimleague.com/events/atr-gt3-2023-h2/round-01""))," & Chr(13) & "" & Chr(10) & " Data2 = Source{2}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data2,{{""#"", type text}, {""Driver"", type text}, {""Car"", type text}, {""Grid position"", type text}, {""Laps"", Int64.Type}, {""Total time"", type text}, {""Avg.Lap"", type text}, {""Fa" & _
"stest sectors"", type text}, {""Optimal"", type text}, {""Fastest lap"", type text}, {""Tot.Points"", Int64.Type}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table 2"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Table 2]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_2"
.Refresh BackgroundQuery:=False
End With
End Sub