
1.3 Import XML into Excel using VBA from Website ThisWorkbook.Sheets(2).Cells(iRow, iCol) = xmlData.Textīefore executing the code above, just change the path of the input file in the line, xmlDoc.Load.īy this method, you will be able to import multiple XML files into Excel. ThisWorkbook.Sheets(2).Cells(1, iCol) = xmlData.BaseName 'Read XML Data and Load into Excel Sheet by each Node and Chile Node Now Read Elements One by One into XML DOM Objects 'Load & Wait till complete XML Data is loaded 'Add referece from Menu: "Tools -> References -> Microsoft XML Vn.0"ĭim xmlDoc As MSXML2.DOMDocument, xmlRoot As MSXML2.IXMLDOMNodeĭim xmlNodes As MSXML2.IXMLDOMNode, xmlData As MSXML2.IXMLDOMNode Public Sub Convert_XML_To_Excel_Through_VBA() If it is not just an plain import & you want to process each XML node in code, then this is the most preferred method. This VBA code will import XML to Excel by reading each element or node in it, using object model. Wb.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Sheet2").Range("A1")Įnd Sub 1.2 Advanced method to Read each node in XML file using VBA 'Copy Content from New workbook to current active Worksheet


Set wb = Workbooks.OpenXML(Filename:=xml_File_Path) Xml_File_Path = ThisWorkbook.Sheets(1).Cells(2, 1) 'Load XML Data into a New Workbook - Code from Public Sub Convert_XML_To_Excel_From_Local_Path() This methods import and open XML file in Excel from local path, but it is slightly different from the previous methods.
