1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| Option Explicit
Sub ImportAllData()
Dim DD As String, DF As String, S As String, ReqUrl As String, IeUrl As String
Dim IE As Object, Req As Object
Dim i As Integer, N As Integer
Dim Tb
Application.ScreenUpdating = False
N = 6
DD = Format(DateSerial(2015, 1, 1), "yyyy-mm-dd")
DF = Format(Now, "yyyy-mm-dd")
ReqUrl = "http://www.swapsinfo.org/download/index/cdaf3d57f0bc68356ecf58c4235a8311c10f5d91/CDS%20Market%20Risk%20Activity"
Set Req = CreateObject("microsoft.xmlhttp")
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
For i = 1 To N
DoEvents
IeUrl = "http://www.swapsinfo.org/charts/swaps/market-risk-activity?date_start=" & DD
IeUrl = IeUrl & "&date_end=" & DF & "&products=snre%2Cindex&suggest=&search=" & i
IeUrl = IeUrl & "&type=&submit=Update+Data"
IE.navigate IeUrl
Do Until IE.readyState = 4:
DoEvents
Loop
If InStr(IE.document.body.innertext, "No data was returned. Please modify your filter parameters.") = 0 Then
With Req
.Open "GET", ReqUrl, False
.Send
S = .Responsetext
End With
Tb = Split(S, vbLf)
With ThisWorkbook
With .Sheets.Add(After:=.Sheets(.Sheets.Count)).Cells(1, 1).Resize(UBound(Tb) + 1)
.Value = Application.Transpose(Tb)
.TextToColumns Destination:=.Cells(1, 1), DataType:=xlDelimited, Comma:=True, FieldInfo:=Array(Array(1, 5), Array(2, 1), Array(3, 1))
End With
End With
End If
Next i
IE.Quit
Set IE = Nothing
Set Req = Nothing
End Sub |
Partager