您好我试图通过VBA将我从HTTP请求获得的一串csv放入excel电子表格中,即使用
request = CreateObject("WinHttp.WinHttpRequest.5.1")
并将响应传递给字符串对象。我想知道是否有更好的方法,只是通过用新行分割字符串然后再用逗号再分割每一行来加倍循环字符串。
答案 0 :(得分:0)
尝试以下方法:
Dim csv As String
csv = "" 'get the CSV into this variable
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2
Dim txt As Object
Set txt = fso.OpenTextFile("c:\output.csv", ForWriting, True)
txt.Write csv
txt.Close
Set txt = Nothing
Dim xlApp As New Excel.Application 'This may not be necessary if this code is running within an existing Excel application
xlApp.Workbooks.OpenText "c:\output.csv"
您可能需要对OpenText
的参数进行一些调整。
参考文献: