I am getting an error 438 - object doesn't support this property or method when findChildren() is called. It doesn't seem to have issues on how i declared or set my variables so not sure why it doesn't like the function call. It doesn't even get inside the function either before erroring out.
Also when i print the nodes base for root and child it prints just fine so i know something exists there and its successfully grabbing the node.
Option Explicit
Sub TestXML()
On Error GoTo ErrHandle
Dim XDoc As New MSXML2.DOMDocument60
Dim root As IXMLDOMNode
Dim firstChild As IXMLDOMNode
XDoc.async = False: XDoc.validateOnParse = False
XDoc.Load (ThisWorkbook.Path & "\test.xml")
'Get Document Elements
Set root = XDoc.DocumentElement
Set firstChild = root.firstChild
Debug.Print "---Begin New---"
Debug.Print root.BaseName
Debug.Print root.Text
Debug.Print firstChild.BaseName
Debug.Print firstChild.Text
findChildren (firstChild)
Set XDoc = Nothing
Exit Sub
ErrHandle:
MsgBox Err.Number & " - " & Err.Description, vbCritical
Exit Sub
End Sub
Function findChildren(x As IXMLDOMNode)
If x.HasChildNodes() Then
findChildren (x)
ElseIf (x.NextSibling <> Null) Then
findChildren (x.NextSibling)
Debug.Print "[" & x.NextSibling.BaseName & "] = [" & x.NextSibling.Text & "]"
Else
Debug.Print "[" & x.BaseName & "] = [" & x.Text & "]"
End If
End Function