通過以下代碼,我從一個morningstar.com CSV文件導入數據,數據由逗號分隔。一些數據包含逗號的問題。vba分割數據,但逗號跳過引號
例如,「XX,XXX」。 這種情況的結果是:
cell1(X1,Y1)="XX cell(X1,Y2)=XXX" instead of: cell1(X1,Y1)=XX,XXX
我VBA
Sub GetKeyRatios()
Dim URL As String, csv As String, Lines, Values
Dim i As Long, j As Long, WinHttpReq As Object
Dim rngStart As Range
URL = "http://financials.morningstar.com/ajax/exportKR2CSV.html?&callback=?&t=XNYS:JNJ®ion=usa&culture=en-US&cur=USD&order=asc"
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", URL, False
WinHttpReq.send
csv = WinHttpReq.responseText
Lines = Split(csv, vbLf)
Set rngPaste = Sheets("KeyRatios").Range("A1")
For i = 0 To UBound(Lines)
Values = Split(Lines(i), ",")
For j = 0 To UBound(Values)
rngPaste.Offset(i, j).Value = Values(j)
Next j
Next i
End Sub
有沒有辦法做到這一點? attached example
可以打開'.csv'直接'workbooks.Open(「http://financials.morningstar.com/ajax/exportKR2CSV.html?&callback=?&t=XNYS:JNJ®ion=usa&culture=en- US&cur = USD&order = asc「)' – Slai
你可以發佈一些原始數據嗎? – nightcrawler23
好主意,它的效果很好 –