OpenXML Method

Microsoft Excel Visual Basic

Show All Show All

OpenXML Method

Note  XML features, except for saving files in the XML Spreadsheet format, are available only in Microsoft Office Professional Edition 2003 and Microsoft Office Excel 2003.

Opens an XML data file. Returns a Workbook object.

expression.OpenXML(Filename, Stylesheets, LoadOption)

expression    Required. An expression that returns one of the objects in the Applies To list.

FileName   Required String. The name of the file to open.

Stylesheets   Optional Variant. Either a single value or an array of values that specify which XSL Transformation (XSLT) stylesheet processing instructions to apply.

LoadOption   Optional Variant. Specifies how Excel opens the XML data file. Can be one of the XlXmlLoadOption constants.

XlXmlLoadOption can be one of these XlXmlLoadOption constants:
xlXmlLoadImportToList Places the contents of the XML data file in an XML list.
xlXmlLoadMapXml Displays the schema of the XML data file in the XML Structure task pane.
xlXmlLoadOpenXml Opens the XML data file. The contents of the file will be flattened.
xlXmlLoadPromptUser Prompts the user to choose how to open the file.

Example

The following code opens the XML data file "customers.xml" and displays the file's contents in an XML list.

Sub UseOpenXML()
    Application.Workbooks.OpenXML _
        Filename:="customers.xml", _
        LoadOption:=xlXmlLoadImportToList
End Sub