Parameters 对象 (Excel)Parameters object (Excel)

指定的查询表的**Parameter** 对象的集合。A collection of Parameter objects for the specified query table.


每一个 Parameter 对象都代表一个查询参数。Each Parameter object represents a single query parameter. 每一个查询表都包含一个 Parameters 集合,但集合是空的,除非查询表使用的是参数查询。Every query table contains a Parameters collection, but the collection is empty unless the query table is using a parameter query.

您不能在 URL 连接查询表上使用 Add 方法。You cannot use the Add method on a URL connection query table. 对于 URL 连接查询表, Microsoft Excel 将根据**connection** 和**PostText** 属性创建参数。For URL connection query tables, Microsoft Excel creates the parameters based on the Connection and PostText properties.


使用查询表对象的**parameters** 属性可返回Parameters集合。 ****Use the Parameters property of the QueryTable object to return the Parameters collection.

下例显示查询表一中的参数个数。The following example displays the number of parameters in query table one.

MsgBox Workbooks(1).ActiveSheet.QueryTables(1).Parameters.Count

使用Add方法可为查询表创建新的参数。Use the Add method to create a new parameter for a query table. 下面的示例更改查询表一的 SQL 语句。The following example changes the SQL statement for query table one. 子句 "(city =?)" 指示查询是参数查询, "city" 的值设置为常量 Oakland。The clause "(city=?)" indicates that the query is a parameter query, and the value of city is set to the constant Oakland.

Set qt = Sheets("sheet1").QueryTables(1) 
qt.Sql = "SELECT * FROM authors WHERE (city=?)" 
Set param1 = qt.Parameters.Add("City Parameter", _ 
param1.SetParam xlConstant, "Oakland" 



另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.