PDA

View Full Version : xml to vba listbox



cavacuz
12-10-2007, 10:51 AM
Hi ppl!

I am trying to develop an excel workbook that should have a listbox that have to be populated from a xml file.

I have searched millions of sites, foruns, and can't get no example that works.

Can anyone help me?

Thanks anyway.

figment
12-10-2007, 02:45 PM
i have not done anything with xml files, but a here are a few sites that might help

http://www.ozgrid.com/forum/showthread.php?t=27818
http://en.allexperts.com/q/XML-1469/Manipulating-XML-files-Excel.htm

from the little bit that i read it looks like it might be easyest to bring the data into excel then load it into the listbox. it would help if i knew what the xml file you were using looked like. also is the list box an object on the sheet or are you using data validation to turn a cell into a listbox?

Bob Phillips
12-10-2007, 03:34 PM
How about just reading it in VBA, it s just a text file, and pase the data and load the listbox from there.

cavacuz
12-17-2007, 10:44 AM
Hi vba ppl!

I have found something that are working:


Sub ler_xml()
Dim xmldoc As MSXML2.DOMDocument
Set xmldoc = New MSXML2.DOMDocument
Dim root As IXMLDOMElement
Dim oNodeList As IXMLDOMNodeList
Dim item As IXMLDOMNode
Dim subitem As IXMLDOMNode
Dim myarray As Variant

xmldoc.async = False
xmldoc.Load ("c:\T-Pedidos\Obras.xml")
Set root = xmldoc.documentElement
Set oNodeList = root.childNodes

For Each item In oNodeList
UserForm2.ListBox1.AddItem (item.childNodes.item(1).Text & " | " & item.childNodes.item(2).Text & " | " & item.childNodes.item(3).Text)

Next
End Sub


Right now i am searching for a way to perform a search/filter in a userform/listbox.

If somebody knows how please tell me.

Good Codes For Everybody!

stanl
12-17-2007, 11:20 AM
Right now i am searching for a way to perform a search/filter in a userform/listbox.

If somebody knows how please tell me.


If you design your listbox to be more of a 'results' box, you can use xPath for searches and filters. .02 Stan

cavacuz
12-18-2007, 03:19 AM
If you design your listbox to be more of a 'results' box, you can use xPath for searches and filters. .02 Stan

Hi stan!

What i am trying to do is perform a search/filter in a listbox populated from a xml.