2022. 7. 3.

Loading xml data in excel vba by using XML Object(MSXML2.DOMDocument)

### in excel file ( xlsm , macro excel , enable macro) 


' Declare xml object

  set xmlObj = CreateObject("MSXML2.DOMDocument.6.0")

 ' set loading option with non async

 xmlObj.Async = False

' validate off

xmlObj.validateOnParse = False

' reading file from sample.xml 

xmlObj.Load "sample.xml"

' select all "mynode" from root node recursively ( ref. xml path grammar in detail)

' root node에서 mynode 모두 선택하기 추가적인 부분은 xml path 문법을 참고

Set nodeList = xmlObj.SelectNodes("//mynode")

for index to nodeList.Length -1 

    set myNode = nodeList(index)

    ' do somthing 

    aa = myNode.text

next index