Selection.InsertXML method (Word)

Inserts the specified XML into the document at the cursor, replacing any selected text.

Syntax

expression. InsertXML( _XML_ , _Transform_ )

expression An expression that returns a Selection object.

Parameters

Name Required/Optional Data type Description
XML Required String Specifies the XML to insert. This can be any valid custom XML.
Transform Optional Variant Specifies the XML Transformation (XSLT) used to transform the XML. If omitted, the XML is inserted as custom XML without applying a transform.

Return value

Nothing

Example

The following example inserts the specified XML string into the document at the cursor, or replacing the active selection.

Dim strXML As String 
 
strXML = "<"xml version=""1.0""><abc:books xmlns:abc=""urn:books"" " & _ 
 "xmlns:xsi=""https://www.w3.org/2001/XMLSchema-instance"" " & _ 
 "xsi:schemaLocation=""urn:books books.xsd""><book>" & _ 
 "<author>Matt Hink</author><title>Migration Paths of the Red " & _ 
 "Breasted Robin</title><genre>non-fiction</genre>" & _ 
 "<price>29.95</price><pub_date>2006-05-01</pub_date>" & _ 
 "<abstract>You see them in the spring outside your windows. " & _ 
 "You hear their lovely songs wafting in the warm spring air. " & _ 
 "Now follow their path as they migrate to warmer climes in the fall, " & _ 
 "and then back to your back yard in the spring.</abstract></book></abc:books>" 
 
Selection.InsertXML strXML

See also

Selection Object

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.