S
SteveP
In vbs, I can parse an XML file with the following code:
Set xmlDoc = CreateObject("MSXML2.DOMDocument.4.0")
If (IsObject(xmlDoc) = False) Then
alert("DOM document not created. Check MSXML version used in
createXmlDomDocument.")
End If
xmlDoc.async = False
xmlDoc.validateOnParse=False
xmlDoc.load xmlFile
If xmlDoc.parseError.errorcode = 0 Then
'Walk from the root to each of its child nodes:
treeWalk(xmlDoc)
Else
Wscript.echo "There was an error in : " & xmlFile &" Line: " &
xmlDoc.parseError.line & " Column: " & xmlDoc.parseError.linepos
End If
Function treeWalk(node)
For Each child In node.childNodes
If (child.hasChildNodes) Then
treeWalk(child)
End If
Next
End Function
When I try to do this in Excel VBA, it chokes on the line "treeWalk(xmlDoc)"
saying Object doesn't support this property or method. I tried changing the
function definition to include As all-sorts-of-things, no change. I do have
Microsoft XML 4.0 included in the VBA Project References.
I'm obviously overlooking something basic (Visually Basic, that is). Can
someone point me in the right direction?
Set xmlDoc = CreateObject("MSXML2.DOMDocument.4.0")
If (IsObject(xmlDoc) = False) Then
alert("DOM document not created. Check MSXML version used in
createXmlDomDocument.")
End If
xmlDoc.async = False
xmlDoc.validateOnParse=False
xmlDoc.load xmlFile
If xmlDoc.parseError.errorcode = 0 Then
'Walk from the root to each of its child nodes:
treeWalk(xmlDoc)
Else
Wscript.echo "There was an error in : " & xmlFile &" Line: " &
xmlDoc.parseError.line & " Column: " & xmlDoc.parseError.linepos
End If
Function treeWalk(node)
For Each child In node.childNodes
If (child.hasChildNodes) Then
treeWalk(child)
End If
Next
End Function
When I try to do this in Excel VBA, it chokes on the line "treeWalk(xmlDoc)"
saying Object doesn't support this property or method. I tried changing the
function definition to include As all-sorts-of-things, no change. I do have
Microsoft XML 4.0 included in the VBA Project References.
I'm obviously overlooking something basic (Visually Basic, that is). Can
someone point me in the right direction?