CustomXMLNode.InsertSubtreeBefore method (Office)

Inserts the specified subtree into the location just before the context node.

Syntax

expression.InsertSubtreeBefore (XML, NextSibling)

expression An expression that returns a CustomXMLNode object.

Parameters

Name Required/Optional Data type Description
XML Required String Represents the subtree to be added.
NextSibling Optional CustomXMLNode Specifies the context node.

Remarks

If the NextSibling parameter is not a child of the context node, or if the operation would result in an invalid tree structure, the insertion is not performed and an error message is displayed.

Example

The following example adds a custom part and then finds a node in that part by using an XPath expression. The code then inserts a node after the found node.

Dim cxp1 As CustomXMLPart 
Dim cxn As CustomXMLNode 
 
With ActiveDocument 
 
   ' Add a custom xml part. 
   .CustomXMLParts.Add "<invoice>"         
 
   ' Returns the first custom xml part with the given root namespace. 
   Set cxp1 = .CustomXMLParts("urn:invoice:namespace")              
  
   ' Get nodes using XPath.                              
   Set cxn = cxp1.SelectSingleNode("//*[@supplier = "Contoso"]")  
  
   ' Insert a node before the single node selected previously. 
    cxn.InsertNodeAfter("discount", "urn:invoice:namespace")   
              
 End With

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.