|
本帖最后由 buzhidaoaaa 于 2017-12-21 22:29 编辑
有一批xml,直接用excel导入,导入以后数据是乱的,主要是很多不是我想要的数据。想到用vba读到表格里面。
网上找了好多示例,但是到对xml进行操作时就会报错。
Sub xx()
Dim oxmlDoc As DOMDocument
Dim Node As IXMLDOMNode
Dim oXmlNodes As IXMLDOMNodeList
Set oxmlDoc = New DOMDocument
oxmlDoc.async = False
'Rows("1:1").Select
m = Dir(ThisWorkbook.Path & "\*.xml")
Do While m <> ""
oxmlDoc.Load ThisWorkbook.Path & "\" & m
j2 = Range("a65536").End(xlUp).Row + 1
Set oXmlNodes = oxmlDoc.SelectNodes("/extraction/编号/item")
For i = 0 To oXmlNodes(0).ChildNodes.Length - 1
Cells(j2, i + 1) = oXmlNodes(0).ChildNodes(i).Text ‘F8到这里报错。
Next
m = Dir
Loop
For i = 0 To oXmlNodes(0).ChildNodes.Length - 1
Cells(1, i + 1) = oXmlNodes(0).ChildNodes(i).nodeName
Next
End Sub
|
|