3rd June 2009, 02:46 PM
|
Member
|
|
Join Date: Jan 1970
Location: Western Australia
Posts: 3,457
|
|
If i am working on another sheet and the macro starts i get an error because i am not on the active sheet that the web query wants to download to i added a sheet select code but all that does is change to the correct sheet, how can i get it to work no matter what sheet i am working on?
Code:
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
If Len(Range("$AZ$54").Value) = 0 Then GoTo Xit
Sheets("Data-Config").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.betchoice.com/racing/betting.asp?eventid=" & Range("$AZ$54").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
If Len(Range("$BB$54").Value) = 0 Then GoTo Xit
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.**************.com.au/form-guide/race/" & Range("$BB$54").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
|