Importing data from XML file into Excel

raj_rk

New Member
Joined
Aug 9, 2016
Messages
1
Hello All,

I'm a novice in VBScript and XML coding.However, getting my head around and going through online forums and blogs

I want to read/parse an xml file using VBScript,my XML file is not data but xml source code from an application.
Below is the code snippet that I'm using -


Sub LoadXMLFile()


Dim objXML 'for xml document
Dim objNode 'for xml node item
Dim i As Integer
i = 0


Set objXML = CreateObject("Microsoft.XMLDOM")
objXML.Load ("C:\path\test.xml")
objXML.setProperty "SelectionLanguage", "XPath"
Set objNode = objXML.SelectNodes("/report/queries/query/selection/dataItem/text()")
'MsgBox objNode.Text


For i = 0 To (objNode.Length - 1)
NodeVal = objNode(i).NodeValue
MsgBox NodeVal
Next


End Sub

When I step through the VB code the objNode.Length value always evaluates to 0. Not sure why its not calculating the Length.
Appreciate your time and response.
Thanks & Regards
Raj
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,215,176
Messages
6,123,470
Members
449,100
Latest member
sktz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top