|
-
Jul 12th, 2012, 08:06 PM
#1
Thread Starter
New Member
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:
Sub webquery()
startrow = 1
For i = 1 To 55
If i = 1 Then
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"
Else
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"
End If
With ActiveSheet.QueryTables.Add(Connection:=curl, Destination:=Range("$A$" & startrow))
.Name = "Webquery" & i
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "3"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
startrow = startrow + 202
Next i
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:
Sub webquery2()
startrow = 1
For i = 1 To 55
If i = 1 Then
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"
Else
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"
End If
With ActiveSheet.QueryTables.Add(Connection:=curl, Destination:=Range("$A$" & startrow))
.Name = "Webquery2" & i
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "3"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
startrow = startrow + 202
Next i
End Sub
___________________________________________
Last edited by Hack; Jul 13th, 2012 at 05:53 AM.
Reason: Added Highlight Tags
-
Jul 12th, 2012, 08:20 PM
#2
-
Jul 12th, 2012, 08:23 PM
#3
Thread Starter
New Member
Re: Data from web
You mean the URL ? I have used the latest URL by visiting the web site.
-
Jul 13th, 2012, 03:59 AM
#4
Re: Data from web
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
-
Jul 13th, 2012, 04:06 AM
#5
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|