全部显示

CommandType 属性

       

返回或设置下表中列出的 XlCmdType 常量之一。返回或设置的常量用于描述 CommandText 属性的值。默认值为 xlCmdSQLXlCmdType 类型,可读写。

expression.CommandType

说明

只有当查询表或数据透视表高速缓存的 QueryType 属性值为 xlOLEDBQuery 时,才可设置 CommandType 属性。

CommandType 属性的值为 xlCmdCube,如果没有与查询表相关联的数据透视表,则不能更改 CommandType 属性的值。

示例

本示例设置第一张查询表的 ODBC 数据源的命令串。该命令串是一个 SQL 语句。

Set qtQtrResults = _
    Workbooks(1).Worksheets(1).QueryTables(1)
With qtQtrResults
    .CommandType = xlCmdSQL
    .CommandText = _
        "Select ProductID From Products Where ProductID < 10"
    .Refresh
End With