View Single Post
 
Old 06-07-2017, 03:49 AM
slaycock slaycock is offline Windows 7 64bit Office 2013
Expert
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

I watched this excellent video on reading xml values from CustomXMLParts

http://ericwhite.com/blog/screen-cas...sing-word-vba/

I copied the code from the video to have a play around but I get an error where the author of the video doesnt

Code:
Sub xmlreadexample()

Dim sNS         As String
Dim sNSCustom   As String
Dim sNSPrefix   As String

Dim part        As CustomXMLParts
Dim parts       As CustomXMLParts


Dim nodes       As CustomXMLNodes
Dim node        As CustomXMLNode

    Set parts = ThisDocument.CustomXMLParts
    
    sNSCustom = "http://example.com/arc"

    For Each part In parts
        sNS = part.NamespaceURI
        If Len(sNS) = 0 Then
            Set nodes = part.SelectNodes("/arcRoot/arcProperties")
            If nodes.count > 0 Then
                For Each node In nodes
                    Debug.Print "NodeValue     = " & node.NodeValue
                    Debug.Print "NodeText      = " & node.Text
                    Debug.Print "Attribute no  = " & node.Attributes.count
                    For i = 1 To node.Attributes.count
                        Debug.Print "    Attrib name    = " & node.Attributes.Item(i).BaseName
                        Debug.Print "    Attrib value   = " & node.Attributes.Item(i).Text
                    Next i
                Next node
            End If
        Else
            If StrComp(sNS, sNSCustom, vbTextCompare) - 0 Then
                sNSPrefix = part.NamespaceManager.LookupPrefix(sNS)
                Set nodes = part.SelectNodes("/" & sNSPrefix & ":" & "arcRoot/arcProperties")
                If nodes.count > 0 Then
                    For Each node In nodes
                        Debug.Print "NodeValue     = " & node.NodeValue
                        Debug.Print "NodeText      = " & node.Text
                        Debug.Print "Attribute no  = " & node.Attributes.count
                        For i = 1 To node.Attributes.count
                            Debug.Print "    Attrib name    = " & node.Attributes.Item(i).BaseName
                            Debug.Print "    Attrib value   = " & node.Attributes.Item(i).Text
                        Next i
                    Next node
                End If
            End If
        End If
    Next
                    
            
End Sub
The error is a the line

sNS = part.NamespaceURI

and the error is 'Method or data member not found'

This CustomXMLPart stuff does seem to be fraught with multiple issues.

Can anyone shed any light on the above.

The only XML reference I have selected is MicrosoftXML v6.0
Reply With Quote