Macro Problem

Discuss anything related to using the program (eg. triggered betting tactics)

Moderator: 2020vision

Macro Problem

Postby Shaun » Mon Jun 01, 2009 9:25 am

I am still having problems getting this to run, this code does pretty much what i need but i have 2 problems with it.

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
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby dgs2001 » Mon Jun 01, 2009 9:53 am

I'm not 100% sure but this may be a problem
Code: Select all
 
Application.Calculation = xlCalculationManual


then
Code: Select all
 
Application.Calculation = xlCalculationAutomatic


I think this causes a recalculation every time the macro exits, this in turn restarts the macro, hence the frozen state as it loops permanently.

try removing these two lines as they are not necessary because you also use
Code: Select all

Application.EnableEvents = False

'''''    other code here    '''''''

Application.EnableEvents = True



Duncan
User avatar
dgs2001
 
Posts: 334
Joined: Thu Apr 05, 2007 4:53 pm
Location: The Home Of National Hunt

Postby Shaun » Mon Jun 01, 2009 12:21 pm

I have removed all the calculation part of the code and tried to run the import code by itself but it still hangs, i have some lookup formulas on th sheet but they fail to work untill i exit the sheet.

Code: Select all
Sub Worksheet()

 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


End Sub

Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby Ian » Mon Jun 01, 2009 12:36 pm

Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic


Try reversing these statements.
Ian
 
Posts: 834
Joined: Sat Nov 19, 2005 8:35 am
Location: Birmingham

Postby Shaun » Mon Jun 01, 2009 1:26 pm

I am a bloody idiot, i still need to test it some more but i found the problem of the freezing, it was due to a space in a formula this is what i had.
=VLOOKUP(AY53,$BE$56:$BK$102,6, FALSE)

this is what it should have been

=VLOOKUP(AY53,$BE$56:$BK$102,6,FALSE)

I have been trying to sort this out for 4 days, lets see if i can get things working now.
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby dgs2001 » Mon Jun 01, 2009 1:26 pm

yes as ian says reverse the statements.

my previous post was not very clear, sorry.

To explain the
Code: Select all
Application.EnableEvents = false
statement prevents excel from re-calculating the sheet or indeed as it states prevents any application event from triggering, thus allowing your macro code to complete without calling any other macro's or routines.
At the end of your macro the
Code: Select all
 Application.EnableEvents = True
statement then resets excel to allow re-calculating or any other application event.

So this is really the only statement you needed out of the two you had in your original code.

hope this is clearer.

As a by the way - If you stop your macro from completing at any time ie it has gone passed the Application.enableEvents = false but has not reached the Application.enableEvents = true then excel will hold the value of false for application enable events the same is true of Application.Calculation = manual.

I used to be forever pulling my hair out when VBA would not work and seemed to stall etc when really it was because I left Application level events set to manual or off :?
Duncan
User avatar
dgs2001
 
Posts: 334
Joined: Thu Apr 05, 2007 4:53 pm
Location: The Home Of National Hunt

Postby Roger » Mon Jun 01, 2009 2:49 pm

Re: extra space in the formula, Excel is not sensitive to any extra spaces as far as I am aware - I often add spaces when testing to make the structure clearer.
Roger
 
Posts: 140
Joined: Fri Nov 18, 2005 10:45 pm


Return to Discussion

Who is online

Users browsing this forum: Majestic-12 [Bot] and 43 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.