Results 1 to 5 of 5

Thread: Data from web

  1. #1
    New Member
    Join Date
    Jul 12
    Location
    Dubai
    Posts
    3

    Data from web

    I am new to VBA and trying to use it to get web data of batting, bowling data of players. For batting, the following code has been used and it worked.
    vb Code:
    1. Sub webquery()
    2.   startrow = 1
    3.   For i = 1 To 55
    4.     If i = 1 Then
    5.       curl = "URL;http://stats.espncricinfo.com/ci/engine/stats/index.html?class=2;filter=advanced;orderby=start;size=200;spanmax1=30+Jun+2012;spanmin1=01+Jan+2009;spanval1=span;template=results;type=batting;view=innings;wrappertype=print"
    6.     Else
    7.       curl = "URL;http://stats.espncricinfo.com/ci/engine/stats/index.html?class=2;filter=advanced;orderby=start;page=" & i & ";size=200;spanmax1=30+Jun+2012;spanmin1=01+Jan+2009;spanval1=span;template=results;type=batting;view=innings;wrappertype=print"
    8.     End If
    9.    
    10.     With ActiveSheet.QueryTables.Add(Connection:=curl, Destination:=Range("$A$" & startrow))
    11.         .Name = "Webquery" & i
    12.         .FieldNames = True
    13.         .RowNumbers = False
    14.         .FillAdjacentFormulas = False
    15.         .PreserveFormatting = True
    16.         .RefreshOnFileOpen = False
    17.         .BackgroundQuery = True
    18.         .RefreshStyle = xlInsertDeleteCells
    19.         .SavePassword = False
    20.         .SaveData = True
    21.         .AdjustColumnWidth = True
    22.         .RefreshPeriod = 0
    23.         .WebSelectionType = xlSpecifiedTables
    24.         .WebFormatting = xlWebFormattingNone
    25.         .WebTables = "3"
    26.         .WebPreFormattedTextToColumns = True
    27.         .WebConsecutiveDelimitersAsOne = True
    28.         .WebSingleBlockTextImport = False
    29.         .WebDisableDateRecognition = False
    30.         .WebDisableRedirections = False
    31.         .Refresh BackgroundQuery:=False
    32.     End With
    33.     startrow = startrow + 202
    34.   Next i
    35. End Sub
    _____________________________________________________

    Now to obtain bowling data, I used the following code and it failed due to run time error 1004. I want some expert to correct the mistake.
    vb Code:
    1. Sub webquery2()
    2.   startrow = 1
    3.   For i = 1 To 55
    4.     If i = 1 Then
    5.       curl = "http://stats.espncricinfo.com/ci/engine/stats/index.html?class=2;filter=advanced;orderby=start;size=200;spanmax1=30+Jun+2012;spanmin1=01+Jan+2009;spanval1=span;template=results;type=bowling;view=innings;wrappertype=print"
    6.     Else
    7.       curl = "http://stats.espncricinfo.com/ci/engine/stats/index.html?class=2;filter=advanced;orderby=start;page=2;size=200;spanmax1=30+Jun+2012;spanmin1=01+Jan+2009;spanval1=span;template=results;type=bowling;view=innings;wrappertype=print"
    8.     End If
    9.    
    10.     With ActiveSheet.QueryTables.Add(Connection:=curl, Destination:=Range("$A$" & startrow))
    11.         .Name = "Webquery2" & i
    12.         .FieldNames = True
    13.         .RowNumbers = False
    14.         .FillAdjacentFormulas = False
    15.         .PreserveFormatting = True
    16.         .RefreshOnFileOpen = False
    17.         .BackgroundQuery = True
    18.         .RefreshStyle = xlInsertDeleteCells
    19.         .SavePassword = False
    20.         .SaveData = True
    21.         .AdjustColumnWidth = True
    22.         .RefreshPeriod = 0
    23.         .WebSelectionType = xlSpecifiedTables
    24.         .WebFormatting = xlWebFormattingNone
    25.         .WebTables = "3"
    26.         .WebPreFormattedTextToColumns = True
    27.         .WebConsecutiveDelimitersAsOne = True
    28.         .WebSingleBlockTextImport = False
    29.         .WebDisableDateRecognition = False
    30.         .WebDisableRedirections = False
    31.         .Refresh BackgroundQuery:=False
    32.     End With
    33.     startrow = startrow + 202
    34.   Next i
    35. End Sub
    ___________________________________________
    Last edited by Hack; Jul 13th, 2012 at 05:53 AM. Reason: Added Highlight Tags

  2. #2
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    Re: Data from web

    Thread moved

  3. #3
    New Member
    Join Date
    Jul 12
    Location
    Dubai
    Posts
    3

    Re: Data from web

    You mean the URL ? I have used the latest URL by visiting the web site.

  4. #4
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,524

    Re: Data from web

    You mean the URL ?
    no, he means this question has been moved to the correct forum

    which line gives error?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    New Member
    Join Date
    Jul 12
    Location
    Dubai
    Posts
    3

    Re: Data from web

    I have noted that in the second macro, I have omitted the word URL just before the actual URL. Once this is put in, macro works fine.

    Ofcourse, I do have couple of problems still.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •