ConradBartimus
New Member
- Joined
- Sep 19, 2015
- Messages
- 24
Hey Guys,
I am trying to teach myself VBA queries and I wanted to ask 2 questions. First question, I have all my web queries build into connections on a workbook. BUT I want to learn how to do this same thing but in VBA and then I want to test speeds of refreshes (as I have heard it is faster). How can I grab specific tables in a VBA built web query like I can with regular web queries.
Here is what I have so far vs what I had build in a web querie:
VBA:
Sub Refresh()
Application.ScreenUpdating = False
Worksheets("Eligibilities").Visible = True
'urlstr
Dim urlStr As String
' show sht as worksheet
Dim sht As Worksheet
'label the sht
Set sht = Sheets("Eligibilities")
'This information changes settings of URL
fc = Worksheets("Start Up").Cells(3, "D").Value
'*************Start URL Code
urlStr = "https://" & fc & "-portal.barnes.com/gp/picking/config/pickerEligibilities.html"
'*************End url code
sht.Columns("A:BE").ClearContents
With sht.QueryTables.Add(Connection:="URL;" & urlStr, Destination:=Worksheets("Eligibilities").Range("$A$1"))
.Name = "default"
.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
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Application.Run ("delete_Connections")
Worksheets("Eligibilities").Visible = False
Application.ScreenUpdating = True
End Sub
Sub delete_Connections()
Do While ActiveWorkbook.Connections.Count > 0
ActiveWorkbook.Connections.Item(ActiveWorkbook.Connections.Count).Delete
Loop
End Sub
Web Query:
WEB
1
https://["fc"]-portal.barnes.com/gp/picking/config/pickerEligibilities.html
Selection=EntirePage
Formatting=None
PreFormattedTextToColumns=True
ConsecutiveDelimitersAsOne=True
SingleBlockTextImport=False
DisableDateRecognition=False
DisableRedirections=False
Secondly, can I make the VBA create multiple queries or do I need to make it loop multiple macros?
I am trying to teach myself VBA queries and I wanted to ask 2 questions. First question, I have all my web queries build into connections on a workbook. BUT I want to learn how to do this same thing but in VBA and then I want to test speeds of refreshes (as I have heard it is faster). How can I grab specific tables in a VBA built web query like I can with regular web queries.
Here is what I have so far vs what I had build in a web querie:
VBA:
Sub Refresh()
Application.ScreenUpdating = False
Worksheets("Eligibilities").Visible = True
'urlstr
Dim urlStr As String
' show sht as worksheet
Dim sht As Worksheet
'label the sht
Set sht = Sheets("Eligibilities")
'This information changes settings of URL
fc = Worksheets("Start Up").Cells(3, "D").Value
'*************Start URL Code
urlStr = "https://" & fc & "-portal.barnes.com/gp/picking/config/pickerEligibilities.html"
'*************End url code
sht.Columns("A:BE").ClearContents
With sht.QueryTables.Add(Connection:="URL;" & urlStr, Destination:=Worksheets("Eligibilities").Range("$A$1"))
.Name = "default"
.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
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Application.Run ("delete_Connections")
Worksheets("Eligibilities").Visible = False
Application.ScreenUpdating = True
End Sub
Sub delete_Connections()
Do While ActiveWorkbook.Connections.Count > 0
ActiveWorkbook.Connections.Item(ActiveWorkbook.Connections.Count).Delete
Loop
End Sub
Web Query:
WEB
1
https://["fc"]-portal.barnes.com/gp/picking/config/pickerEligibilities.html
Selection=EntirePage
Formatting=None
PreFormattedTextToColumns=True
ConsecutiveDelimitersAsOne=True
SingleBlockTextImport=False
DisableDateRecognition=False
DisableRedirections=False
Secondly, can I make the VBA create multiple queries or do I need to make it loop multiple macros?