CustomXMLParts.Add method (Office)

Allows you to add a new CustomXMLPart to a file.


expression.Add (XML, SchemaCollection)

expression An expression that returns a CustomXMLParts object.


Name Required/Optional Data type Description
XML Optional String Contains the XML to add to the newly created CustomXMLPart.
SchemaCollection Optional CustomXMLSchemaCollection Represents the set of schemas to be used to validate this stream.

Return value



The following example adds a new CustomXMLPart, selects a CustomXMLPart by using a search criteria, and then selects a single node from that part.

Sub ShowCustomXmlParts() 
    On Error GoTo Err 
    Dim cxp1 As CustomXMLPart 
    Dim cxn As CustomXMLNode 
    Dim cxns As CustomXMLNodes 
    Dim strXml As String 
    Dim strUri As String 
        ' Example written for Word. 
        ' Add a custom XML part. 
        ActiveDocument.CustomXMLParts.Add "<custXMLPart />" 
        ' Returns the first custom XML part with the given root namespace. 
        Set cxp1 = ActiveDocument.CustomXMLParts("urn:invoice:namespace")         
        ' Get a node using XPath.                              
        Set cxn = cxp1.SelectSingleNode("//*[@quantity < 4]")  
    Exit Sub 
' Exception handling. Show the message and resume. 
        MsgBox (Err.Description) 
        Resume Next 
End Sub

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.