Trying to learn VBA Queries

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?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,223,244
Messages
6,170,976
Members
452,372
Latest member
Natalie18

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