Skip to main content

XPath object

Table of contents
  1. Remarks
  2. Example

Represents an XPath that has been mapped to a Range or ListColumn object.


Use the SetValue method to map an XPath to a range or list column. The SetValue method is also used to change the properties of an existing XPath.

Use the Clear method to remove an XPath that has been mapped to a range or list column.


The following example creates an XML list based on the Contacts schema map that is attached to the workbook, and then uses the SetValue method to bind each column to an XPath.

Sub CreateXMLList()
    Dim mapContact As XmlMap
    Dim strXPath As String
    Dim lstContacts As ListObject
    Dim lcNewCol As ListColumn
    ' Specify the schema map to use.
    Set mapContact = ActiveWorkbook.XmlMaps("Contacts")
    ' Create a new list.
    Set lstContacts = ActiveSheet.ListObjects.Add
    ' Specify the first element to map.
    strXPath = "/Root/Person/FirstName"
    ' Map the element.
    lstContacts.ListColumns(1).XPath.SetValue mapContact, strXPath
    ' Specify the element to map.
    strXPath = "/Root/Person/LastName"
    ' Add a column to the list.
    Set lcNewCol = lstContacts.ListColumns.Add
    ' Map the element.
    lcNewCol.XPath.SetValue mapContact, strXPath
    strXPath = "/Root/Person/Address/Zip"
    Set lcNewCol = lstContacts.ListColumns.Add
    lcNewCol.XPath.SetValue mapContact, strXPath
End Sub

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>