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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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