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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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