Code Snippets


Dim objDOM As DOMDocument40 
Dim sXML As String

sXML = Application.Selection.Range.WordOpenXML
objDOM.LoadXML(sXML)
objDOM.Save("C:\temp\filename")

DocumentFormat.OpenXML ?

Open XML SDK 2.0 productivity Tool for Microsoft Office


Office.CustomXMLPart
Office.CustomXMLNodes
Office.CustomXMLNode


Office.msoCustomXMLNodeType


XML Parts


ActiveDocument.CustomXmlParts.Add 
ActiveDocument.CustomXmlParts(ActiveDocument.CustomXmlParts.Count).Load("C:\temp\mydata.xml")


ActiveDocument.ContentControls(1).XMLMapping.SetMapping "/customer/companyname" 

XML Options dialog
This dialog is accessed from the XML Structure Task Pane and modifies the Task Pane's appearance.


Save data only
ActiveDocument.XMLSaveDataOnly=True


Apply custom transform
ActiveDocument.TransformDocument "c:\path\filename.xsl"


Validate document against attached schemas
ActiveDocument.XMLSchemaReferences.AutomaticValidation = True



Hide schema violations in this document
ActiveDocument.XMLSchemaReferences.HideValidationErrors = True


Ignore mixed content
ActiveDocument.XMLSchemaReferences.IgnoreMixedContent = True


Allow saving as XML even if not valid
ActiveDocument.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = True

Hide namespace alias in XML Structure task pane


ActiveDocument.XMLHideNamespaces = True


Show advanced XML error messages
ActiveDocument.XMLShowAdvancedErrors = True


Show placeholder text for all empty elements
ActiveDocument.XMLSchemaReferences.ShowPlaceholderText = True



Schema Library
This list displays the entries in Application.XMLNamespaces.


To select a filtered list of nodes
ActiveDocument.SelectNode AnXPath,Prefix


To select the first node matching the filter
ActiveDocument.SelectSingleNode AnXPath,Prefix



© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext