PreserveColumnInfo 属性 (Excel)QueryTable.PreserveColumnInfo property (Excel)

如果每次刷新查询表时,列排序、筛选和布局信息都会保留,则该值为 TrueTrue if column sorting, filtering, and layout information is preserved whenever a query table is refreshed. 默认值为 TrueThe default value is True. 读取/写入 BooleanRead/write Boolean.

语法Syntax

表达式PreserveColumnInfoexpression.PreserveColumnInfo

_表达式_一个代表查询表对象**** 的变量。expression A variable that represents a QueryTable object.

说明Remarks

只有当查询表使用数据库连接时,该属性才有效。This property has an effect only when the query table is using a database connection.

可以将该属性设置为 False,以便与 Microsoft Excel 的早期版本兼容。You can set this property to False for compatibility with earlier versions of Microsoft Excel.

如果使用用户界面导入数据, 则会将来自 web 查询或文本查询的数据作为一个查询表**** 对象导入, 而将所有其他外部数据作为**ListObject** 对象导入。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.

如果使用对象模型导入数据, 则必须将来自 web 查询或文本查询的数据作为查询表导入****, 而所有其他外部数据均可作为ListObject或查询表导入。 ****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.

您可以使用ListObject的查询表属性来访问PreserveColumnInfo属性。 You can use the QueryTable property of the ListObject to access the PreserveColumnInfo property.

示例Example

本示例保留列排序、筛选和布局信息,以便与 Microsoft Excel 的早期版本兼容。This example preserves column sorting, filtering, and layout information for compatibility with earlier versions of Microsoft Excel.

Dim cnnConnect As ADODB.Connection 
Dim rstRecordset As ADODB.Recordset 
 
Set cnnConnect = New ADODB.Connection 
cnnConnect.Open "Provider=SQLOLEDB;" & _ 
 "Data Source=srvdata;" & _ 
 "User ID=wadet;Password=4me2no;" 
 
Set rstRecordset = New ADODB.Recordset 
rstRecordset.Open _ 
 Source:="Select Name, Quantity, Price From Products", _ 
 ActiveConnection:=cnnConnect, _ 
 CursorType:=adOpenDynamic, _ 
 LockType:=adLockReadOnly, _ 
 Options:=adCmdText 
 
With ActiveSheet.QueryTables.Add( _ 
 Connection:=rstRecordset, _ 
 Destination:=Range("A1")) 
 .Name = "Contact List" 
 .FieldNames = True 
 .RowNumbers = False 
 .FillAdjacentFormulas = False 
 .PreserveFormatting = True 
 .RefreshOnFileOpen = False 
 .BackgroundQuery = True 
 .RefreshStyle = xlInsertDeleteCells 
 .SavePassword = True 
 .SaveData = True 
 .AdjustColumnWidth = True 
 .RefreshPeriod = 0 
 .PreserveColumnInfo = True 
 .Refresh BackgroundQuery:=False 
End With

支持和反馈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.