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

如果将数据前五行的任何常用格式设置应用到查询表的新数据行,则为 TrueTrue if any formatting common to the first five rows of data are applied to new rows of data in the query table. 未使用的单元格未格式化。Unused cells aren't formatted. 如果将应用到查询表的最新一次自动套用格式应用于新数据行,则属性为 FalseThe property is False if the last AutoFormat applied to the query table is applied to new rows of data. 默认值为 TrueThe default value is True.

语法Syntax

表达式PreserveFormattingexpression.PreserveFormatting

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

说明Remarks

对于数据库查询表, 默认格式设置为xlSimple 常量For database query tables, the default formatting setting is the xlSimple constant.

刷新查询表时,将对查询表应用新的自动套用格式样式。The new AutoFormat style is applied to the query table when the table is refreshed. 只要 PreserveFormatting 的值为 False,则 AutoFormat(自动套用格式)就会被设置为 NoneThe AutoFormat is reset to None whenever PreserveFormatting is set to False. 因此, 在PreserveFormatting之前设置的任何自动套用格式设置为False , 并且在刷新查询表之前不会生效, 并且生成的查询表不会应用任何格式。As a result, any AutoFormat that's set before PreserveFormatting is set to False and before the query table is refreshed doesn't take effect, and the resulting query table has no formatting applied to it.

如果使用用户界面导入数据, 则会将来自 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的查询表属性来访问PreserveFormatting属性。 You can use the QueryTable property of the ListObject to access the PreserveFormatting property.

示例Example

此示例保留第一张工作表上的第一个数据透视表的格式。This example preserves the formatting of the first PivotTable report on worksheet one.

Worksheets(1).PivotTables("Pivot1").PreserveFormatting = True

此示例演示了将 PreserveFormatting 设置为 False 后,如何操作才能将“自动套用格式”设置为 xlRangeAutoFormatNone,而并不是指定的 xlRangeAutoFormatColor1 格式。This example demonstrates how setting PreserveFormatting to False causes the AutoFormat to be set to xlRangeAutoFormatNone instead of the specified xlRangeAutoFormatColor1 format.

With Workbooks(1).Worksheets(1).QueryTables(1) 
 .Range.AutoFormat = xlRangeAutoFormatColor1 
 .PreserveFormatting = False 
 .Refresh 
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.