web query speeds

klatlap

Well-known Member
Joined
Sep 1, 2004
Messages
607
Office Version
  1. 2013
Platform
  1. Windows
Hi, i am just after some information, i use a couple different codes for extracting webpages and am just wanting someone to explain the differences and why one would be better used over the other.

Code:
Public Function ExecuteWebRequest(URL As String) As String
    Dim oXHTTP As Object
    Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
    oXHTTP.Open "GET", URL, False
    oXHTTP.Send
    ExecuteWebRequest = oXHTTP.responseText
    Set oXHTTP = Nothing
End Function

Code:
Public Function outputtext(Text As String)
Dim MyFile As String, fnum As String
        MyFile = ThisWorkbook.Path & "\temp.txt"
        fnum = FreeFile()
        Open MyFile For Output As fnum
        Print #fnum, Text
        Close #fnum
End Function



Code:
Sub WebQuery()
Application.ScreenUpdating = False
    Sheets("Sheet2").Select
    Range("A1:Z500").Value = ""
Sheets("sheet2").Range("A1").Value = Sheets("sheet1").Range("A8").Value
formhtml = ExecuteWebRequest(ThisWorkbook.Sheets("Sheet2").Range("A1").Value)
    outputtext (formhtml)
    Set temp_qt = ThisWorkbook.Sheets("Sheet2").QueryTables.Add(Connection:= _
            "URL;" & ThisWorkbook.Path & "\temp.txt" _
            , Destination:=ThisWorkbook.Sheets("Sheet2").Range("$A$2"))
    With temp_qt
        .RefreshStyle = xlOverwriteCells
        '.WebSelectionType = xlEntirePage
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "2"
        .SaveData = True
        .Refresh BackgroundQuery:=False
        End With
 ActiveSheet.QueryTables.Item(1).Delete
    Set temp_qt = Nothing
 Kill ThisWorkbook.Path & "\temp.txt"
For Each ws In ThisWorkbook.Worksheets
For Each qt In ws.QueryTables
qt.Delete
Next qt
Next ws
If ActiveWorkbook.Connections.Count > 0 Then
For i = 1 To ActiveWorkbook.Connections.Count
ActiveWorkbook.Connections.Item(1).Delete
Next i
End If
End Sub







Code:
Sub ObjWeb()
Application.ScreenUpdating = False
    Sheets("Sheet2").Select
    Range("A1:Z500").Value = ""
Sheets("sheet2").Range("A1").Value = Sheets("sheet1").Range("A8").Value
Dim ObjWeb As QueryTable
Set ObjWeb = ActiveSheet.QueryTables.Add(Connection:="URL;" & ThisWorkbook.Sheets("Sheet2").Range("A1").Value, _
  Destination:=Range("$A$1"))
   With ObjWeb
   .RefreshStyle = xlOverwriteCells
    .WebSelectionType = xlEntirePage
     .WebFormatting = xlWebFormattingNone
      .WebDisableDateRecognition = True
       .SaveData = True
        .Refresh BackgroundQuery:=False
    End With

    Application.ScreenUpdating = True
    For Each ws In ThisWorkbook.Worksheets
For Each qt In ws.QueryTables
qt.Delete
Next qt
Next ws
If ActiveWorkbook.Connections.Count > 0 Then
For i = 1 To ActiveWorkbook.Connections.Count
ActiveWorkbook.Connections.Item(1).Delete
Next i
    End If
    End Sub
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,223,248
Messages
6,171,011
Members
452,374
Latest member
keccles

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