WebQuery

LouLBI

New Member
Joined
Jun 19, 2012
Messages
42
In using a WebQuery, if I use a specific date, the macro works fine as follows

Code:
Sub DerbyLane()
'
'
    Sheets.Add
 
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.derbylane.com/entriesresult/SP08-20-2014AENT.HTM", Destination _
        :=Range("A1"))
        .Name = "SP08-20-2014AENT"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = False
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    End Sub

But when I want to go to a date relative to the current date as follows, it hangs up at
".Refresh BackgroundQuery:=False"

Code:
Sub DerbyLane()
'
'
Sheets.Add

Dim URL As String, theDate As Date
theDate = Date - 1 'yesterday, for example
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.derbylane.com/entriesresult/SP" & Format(theDate, "MM-DD-YYYY") & "eENT.AENT.HTM", Destination _
        :=Range("A1"))
         .Name = "SP08-20-2014AENT"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = False
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    End Sub

This worked at one time, but now it does not.
Thanks
LouLBI
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You have a typo in the second case. Try:

Code:
"URL;http://www.derbylane.com/entriesresult/SP" & Format(theDate, "MM-DD-YYYY") & "AENT.HTM", Destination _
 
Upvote 0
You have a typo in the second case. Try:

Code:
"URL;http://www.derbylane.com/entriesresult/SP" & Format(theDate, "MM-DD-YYYY") & "AENT.HTM", Destination _

Code:
Sub DerbyLane()
'
'
    Sheets.Add
Dim URL As String, theDate As Date
theDate = Date - 1 'yesterday, for example
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.derbylane.com/entriesresult/SP" & Format(theDate, "MM-DD-YYYY") & "AENT.HTM", Destination _
        :=Range("A1"))
    'With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.derbylane.com/entriesresult/SP08-20-2014AENT.HTM", Destination _
        :=Range("A1"))
        .Name = "SP08-20-2014AENT"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = False
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    End Sub
I believe I copied it correctly, but it still does not work
LouLBI
 
Upvote 0
The code worked for me as is, but try this anyway:

Code:
Sub DerbyLane()
'
'
Sheets.Add
Dim URL As String, theDate As Date
theDate = Date - 1 'yesterday, for example
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.derbylane.com/entriesresult/SP" & Format(theDate, "MM-DD-YYYY") & "AENT.HTM", Destination _
        :=Range("A1"))
        .Name = "SP08-20-2014AENT"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = False
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .BackgroundQuery = False
        .Refresh
    End With
    
End Sub
 
Upvote 0
Having trouble with my internet connection on my laptop. Now on my iPad. Will try your suggestion when I resolve the problem.

Thanks
LouLBI
 
Upvote 0

Forum statistics

Threads
1,222,122
Messages
6,164,084
Members
451,872
Latest member
TimothyLynn

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