[英]VBA-Excel: Read Data from XML File
這樣的事情應該為您工作。 請注意,我不必理會每個單元格的格式:首先,請執行以下步驟:單擊工具>引用。 檢查這些庫-Microsoft WinHttp Services版本5.1-Microsoft XML v6.0
Sub TestXML()
URL = "https://example.abc.com" 'Your URL
AuthorizationCode = "Basic <Password>" 'Please put only encrypted password
Dim ws As Worksheet
Dim objHTTP As New WinHttp.WinHttpRequest
Dim jsonString As String
Dim Resp As New DOMDocument
Dim Result As IXMLDOMNode
Dim i As Integer, j As Integer
objHTTP.Open "get", URL, False
objHTTP.SetRequestHeader "Accept", "application/xml"
objHTTP.SetRequestHeader "Content-Type", "application/xml"
objHTTP.SetRequestHeader "Authorization", AuthorizationCode
objHTTP.Send
Debug.Print objHTTP.Status
Debug.Print objHTTP.ResponseText
Set ws = Sheets("sheet1")
ws.Select
Range("A1").Select
Cells.Clear
Resp.LoadXML objHTTP.ResponseText
Set lists = Resp.DocumentElement
x = 2
y = 1
For Each listNode In lists.ChildNodes
x = 2
Cells(1, y).Value = lists.ChildNodes(y - 1).ChildNodes(0).BaseName
For Each fieldNode In listNode.ChildNodes
Cells(x, y).Value = fieldNode.Text
x = x + 1
Next fieldNode
y = y + 1
Next listNode
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.