Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default how to extract XML info with VBA?

Can I use Excel VBA to extract information from an XML file _without_
opening the XML file as a worksheet in Excel? If so...can y'all point me
to some tutorials on the web or to a good book?

I have only Excel 2002 available.

Thank you.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default how to extract XML info with VBA?

Can I use Excel VBA to extract information from an XML file _without_
opening the XML file as a worksheet in Excel? If so...can y'all point me
to some tutorials on the web or to a good book?


I have been using Excel and macros and VBA for many years, but am new to
this XML stuff.

What I have is an XML file generated by another program, that file contains
a wealth of information to be used in a manufacturing plant. I guess I am
expecting to be able to use some sort of functions to extract my desired
information from the "data fields" in the XML file. Maybe I have a totally
wrong impression of what this stuff does.

thanks. Fred.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default how to extract XML info with VBA?

Fred,

You need to establish a reference to the Microsoft MSXML 3.0 or 4.0 Library
and code against it. It has an elaborate object model but you and use it to
do all the programming you need.

Alok Joshi

"Fred Smif" wrote:

Can I use Excel VBA to extract information from an XML file _without_
opening the XML file as a worksheet in Excel? If so...can y'all point me
to some tutorials on the web or to a good book?


I have been using Excel and macros and VBA for many years, but am new to
this XML stuff.

What I have is an XML file generated by another program, that file contains
a wealth of information to be used in a manufacturing plant. I guess I am
expecting to be able to use some sort of functions to extract my desired
information from the "data fields" in the XML file. Maybe I have a totally
wrong impression of what this stuff does.

thanks. Fred.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default how to extract XML info with VBA?

Hi Fred

Here is a simple code only demo that loads the xml and parse the nodes. Set
a reference to Microsoft XML 3 or similar in the Tools References menu.

This demo has no error handling. E.g. "Load" may err if < is not the first
character. Ok:

Sub test()
Dim XMLdok As DOMDocument
Dim XMLRootNode As IXMLDOMNode

Set XMLdok = New DOMDocument
XMLdok.async = False
XMLdok.resolveExternals = False

XMLdok.Load ("C:\Temp\test.xml")

Set XMLRootNode = XMLdok.childNodes(0)
Call TraverseTree(XMLRootNode)

Set XMLRootNode = Nothing
Set XMLdok = Nothing
End Sub

Sub TraverseTree(objNode As IXMLDOMNode)
Dim ThisNode As IXMLDOMNode

Set ThisNode = objNode

Do
On Error Resume Next

MsgBox ThisNode.nodeName & vbNewLine & _
ThisNode.XML & vbNewLine & _
ThisNode.baseName & vbNewLine & _
ThisNode.nodeValue & vbNewLine & _
ThisNode.Text

If Not ThisNode.childNodes(0) Is Nothing Then
Call TraverseTree(ThisNode.childNodes(0))
End If

Set ThisNode = ThisNode.nextSibling
On Error GoTo 0
Loop While Not ThisNode Is Nothing
End Sub

HTH. Best wishes Harald


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract info based on Name khers Excel Discussion (Misc queries) 4 July 25th 11 04:24 PM
Extract info from one sheet to another Kim Excel Worksheet Functions 2 March 15th 08 01:30 PM
Extract some info from a string mathew Excel Discussion (Misc queries) 2 October 11th 06 10:02 PM
Would it be possible to extract info from this site? IntricateFool Excel Discussion (Misc queries) 3 September 14th 06 05:55 PM
extract info to another sheet.. Gordon[_2_] Excel Programming 5 December 20th 04 09:06 PM


All times are GMT +1. The time now is 05:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"