Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Worksheet.XmlDataQuery Method (Excel)

Returns a Range object that represents the cells mapped to a particular XPath. Returns Nothing if the specified XPath has not been mapped to the worksheet, or if the mapped range is empty.

expression .XmlDataQuery(XPath, SelectionNamespaces, Map)

expression A variable that represents a Worksheet object.




Data Type





The XPath to query for.




A space-delimited String that contains the namespaces referenced in the XPath parameter. A run-time error will be generated if one of the specified namespaces cannot be resolved.




Specify an XmlMap if you want to query for the XPath within a specific map.

Return Value


If the XPath exists within a column in an XML list, the Range object returned does not include the header row.

This method returns Nothing if the XPath location path is not mapped into the grid. Thus, a return of Nothing doesn't necessarily mean that the map doesn't exist. It could mean that there is currently no data range available at the specified XPath location. You can use the XmlMapQuery method to check for the existence of a mapped XPath.

Note Note

The XmlDataQuery method allows you to query for the existence of particular map data. It can not be used to query for a piece of data in a map. For example, it is valid for a mapped range to exist in which the XPath for that range is "/root/People[@Age="23"]/FirstName". An XmlDataQuery query for this XPath location path will returnreturns the correct range. However, a query for "/root/People[FirstName="Joe"]" hoping to find "Joe" within the above mapped range will fail because the XPath definitions for the mapped ranges are different.

© 2016 Microsoft