MSXML을 사용하십시오 - Excel VBA IDE의 도구/참조에서 Microsoft XML을 참조해야합니다.
XML (Load
) 또는 문자열 (LoadXML
)에서 XML을로드 할 수 있습니다. 내 예제에서 나는 파일에서로드 :
Option Explicit
Sub TestXML()
'***** Declare document
Dim oXmlDoc As DOMDocument
Dim bRet As Boolean
'***** Create empty document
Set oXmlDoc = New DOMDocument
'***** Load XML from file
bRet = oXmlDoc.Load("c:\temp\test.xml")
'***** Manipulate XML
MsgBox oXmlDoc.Text
MsgBox oXmlDoc.XML
MsgBox oXmlDoc.SelectSingleNode("//testxml/tests/test[@nr='3']").Text
'***** Clean up
Set oXmlDoc = Nothing
End Sub
:
<?xml version="1.0" encoding="utf-8"?>
<testxml>
<tests>
<test nr="1">Number 1</test>
<test nr="2">Number 2</test>
<test nr="3">Number 3</test>
<test nr="4">Number 4</test>
</tests>
</testxml>
VBA 파일을로드