1) the code freezes the sheet so it won't calculate i need it to run once then stop and wait for another change.
2) When an incorrect url is used i get a no data message, i would like it to ignore the message and make no changes.
As you can see i am importing 2 different web pages each time it runs.
- Code: Select all
Private Sub Worksheet_Calculate()
Static MyMarket As Variant
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
If [A1].Value = MyMarket Then
GoTo Xit
Else
MyMarket = [A1].Value
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.betchoice.com/racing/betting.asp?eventid=" & Range("$AZ$55").Value, _
Destination:=Range("$A$50"))
.Name = "betting"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = """HorseTable"""
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=True
End With
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.way2bet.com.au/form-guide/race/" & Range("$BB$55").Value, _
Destination:=Range("$AP$55"))
.Name = "Form"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "4"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=True
End With
Xit:
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End If
End Sub