CloonanCPA
New Member
- Joined
- Sep 13, 2018
- Messages
- 1
Hello,
I need some help making a macro to extract table data from multiple pages of the same website (see example at https://www(dot)gsaelibrary(dot)gsa...+SERVICES+&+AFFILIATES,+INC.&executeQuery=YES.
I have all the URLs lined up in one row (since the tables I am extracting from the URLS have 2 rows, I used code to insert a blank column between all of my columns with URLs (to give space for 2 rows of data per URL).
When I use the record function for extracting the tables for the first 2 URLS (column A and C), I get the following code:
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+o
'
ActiveCell.FormulaR1C1 = _
"https://www.gsaelibrary.gsa.gov/ElibMain/contractorInfo.do?contractNumber=GS-07F-0361X&contractorName=%27FORE%27+SUPPLY+CO.&executeQuery=YES"
Range("A2").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.gsaelibrary.gsa.gov/ElibMain/contractorInfo.do?contractNumber=GS-07F-0361X&contractorName=%27FORE%27+SUPPLY+CO.&executeQuery=YES" _
, Destination:=Range("$A$2"))
.CommandType = 0
.Name = _
"contractorInfo.do?contractNumber=GS-07F-0361X&contractorName=%27FORE%27+SUPPLY+CO.&executeQuery=YES"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "13"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Range("C1").Select
ActiveCell.FormulaR1C1 = _
"https://www.gsaelibrary.gsa.gov/ElibMain/contractorInfo.do?contractNumber=GS-07F-0386N&contractorName=%27JM%27+TEMPORARY+SERVICES+%26+AFFILIATES%2C+INC.&executeQuery=YES"
Range("C2").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.gsaelibrary.gsa.gov/ElibMain/contractorInfo.do?contractNumber=GS-07F-0386N&contractorName=%27JM%27+TEMPORARY+SERVICES+%26+AFFILIATES%2C+INC.&executeQuery=YES" _
, Destination:=Range("$C$2"))
.CommandType = 0
.Name = _
"contractorInfo.do?contractNumber=GS-07F-0386N&contractorName=%27JM%27+TEMPORARY+SERVICES+%26+AFFILIATES%2C+INC.&executeQuery=YES"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "13"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
Can somebody help me out on here or via email at wcloonan@cloonancpa(dot)com. I would be greatly appreciative.
Thank you so much!
I need some help making a macro to extract table data from multiple pages of the same website (see example at https://www(dot)gsaelibrary(dot)gsa...+SERVICES+&+AFFILIATES,+INC.&executeQuery=YES.
I have all the URLs lined up in one row (since the tables I am extracting from the URLS have 2 rows, I used code to insert a blank column between all of my columns with URLs (to give space for 2 rows of data per URL).
When I use the record function for extracting the tables for the first 2 URLS (column A and C), I get the following code:
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+o
'
ActiveCell.FormulaR1C1 = _
"https://www.gsaelibrary.gsa.gov/ElibMain/contractorInfo.do?contractNumber=GS-07F-0361X&contractorName=%27FORE%27+SUPPLY+CO.&executeQuery=YES"
Range("A2").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.gsaelibrary.gsa.gov/ElibMain/contractorInfo.do?contractNumber=GS-07F-0361X&contractorName=%27FORE%27+SUPPLY+CO.&executeQuery=YES" _
, Destination:=Range("$A$2"))
.CommandType = 0
.Name = _
"contractorInfo.do?contractNumber=GS-07F-0361X&contractorName=%27FORE%27+SUPPLY+CO.&executeQuery=YES"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "13"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Range("C1").Select
ActiveCell.FormulaR1C1 = _
"https://www.gsaelibrary.gsa.gov/ElibMain/contractorInfo.do?contractNumber=GS-07F-0386N&contractorName=%27JM%27+TEMPORARY+SERVICES+%26+AFFILIATES%2C+INC.&executeQuery=YES"
Range("C2").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.gsaelibrary.gsa.gov/ElibMain/contractorInfo.do?contractNumber=GS-07F-0386N&contractorName=%27JM%27+TEMPORARY+SERVICES+%26+AFFILIATES%2C+INC.&executeQuery=YES" _
, Destination:=Range("$C$2"))
.CommandType = 0
.Name = _
"contractorInfo.do?contractNumber=GS-07F-0386N&contractorName=%27JM%27+TEMPORARY+SERVICES+%26+AFFILIATES%2C+INC.&executeQuery=YES"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "13"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
Can somebody help me out on here or via email at wcloonan@cloonancpa(dot)com. I would be greatly appreciative.
Thank you so much!