Results 1 to 5 of 5

Thread: Data from web

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    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

Posting Permissions

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



Click Here to Expand Forum to Full Width