QueryTable.CommandType procedure builder

QueryTable.CommandType (Excel)

Returns or sets one of these XlCmdType constants: xlCmdCube, xlCmdDefault, xlCmdSql, or xlCmdTable. The constant that is returned or set describes the value of the CommandText property. The default value is xlCmdSQL.

xlCmdCube - Contains a cube name for an OLAP data source, xlCmdDAX - Contains a Data Analysis Expressions (DAX) formula, xlCmdDefault - Contains command text that the OLE DB provider understands, xlCmdExcel - Contains an Excel formula, xlCmdList - Contains a pointer to list data, xlCmdSql - Contains an SQL statement, xlCmdTable - Contains a table name for accessing OLE DB data sources, xlCmdTableCollection - Contains the name of a table collection.

You can set the CommandType property only if the value of the QueryType property for the query table or PivotTable cache is xlOLEDBQuery. If the value of the CommandType property is xlCmdCube, you cannot change this value if there is a PivotTable report associated with the query table. If you import data by using the user interface, data from a web query or a text query is imported as a QueryTable object, while all other external data is imported as a ListObject object. If you import data by using the object model, data from a web query or a text query must be imported as a QueryTable, while all other external data can be imported as either a ListObject or a QueryTable. You can use the QueryTable property of the ListObject to access the CommandType property.

ActiveCell.QueryTable.CommandType = xlCmdCube