SlicerCaches 方法 (Excel)SlicerCaches.Add method (Excel)

向集合中添加一个新的**SlicerCache** 对象。Adds a new SlicerCache object to the collection.

语法Syntax

表达式(SourceSourceFieldNameSlicerCacheType)expression.Add (Source, SourceField, Name, SlicerCacheType)

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

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
SourceSource 必需Required VariantVariant 新的SlicerCache对象将基于的数据源。The data source that the new SlicerCache object will be based on. 传给 Source 参数的自变量可以是 WorkbookConnection 对象、PivotTable 对象或字符串。The argument passed to the Source parameter can be a WorkbookConnection object, a PivotTable object, or a string.

如果传递的是数据透视表对象, 则将关联的**PivotCache** 对象用作数据源。If a PivotTable object is passed, the associated PivotCache object is used as the data source. 如果传递的是字符串, 则会将其解释为WorkbookConnection对象的名称, 如果不存在此类WorkbookConnection对象, 则会生成运行时错误。If a string is passed, it is interpreted as the name of a WorkbookConnection object, and if no such WorkbookConnection object exists, a run-time error is generated.
SourceFieldSourceField 必需Required VariantVariant 数据源中要作为筛选依据的字段的名称。The name of the field in the data source to filter by. 对于非 OLAP 数据源, 请使用切片器基于的PivotCache对象中的**透视字段** 对象, 或者该对象的唯一名称 (透视字段的值)。Name 属性)。For non-OLAP data sources, use the PivotField object from the PivotCache object that the slicer is based on, or the unique name of that object (the value of the PivotField.Name property).

对于 OLAP 数据源,应使用 SlicerCache 所基于的层次结构的 MDX 唯一名称。For OLAP data sources, use the MDX unique name of the hierarchy that the SlicerCache is based on. 还可以指定 OLAP 层次结构的一个级别,Excel 将使用对应的层次结构。You can also specify a level of the OLAP hierarchy, and Excel will use the corresponding hierarchy.
NameName 可选Optional VariantVariant Excel 用于引用切片器缓存的名称 ( SlicerCache的值)。Name 属性)。The name that Excel uses to reference the slicer cache (the value of the SlicerCache.Name property). 如果省略此参数,Excel 将生成一个名称。If omitted, Excel will generate a name.

默认情况下, Excel 会将 "Slicer_" 与透视字段的值连接。包含非 OLAP 数据源的切片器的 Caption 属性, 或使用CubeField的值的**Caption** 属性。具有 OLAP 数据源的切片器的**Caption** 属性 (用 "" 替换任何空格)。By default, Excel concatenates "Slicer" with the value of the PivotField.Caption property for slicers with non-OLAP data sources, or with the value of the CubeField.Caption property for slicers with OLAP data sources (replacing any spaces with "_").

)如果需要使该名称在工作簿命名空间中唯一,Excel 会将一个整数添加到生成的名称的末尾。If required to make the name unique in the workbook namespace, Excel adds an integer to the end of the generated name. 如果指定工作簿命名空间中已经存在的名称,Add 方法将失败。If you specify a name that already exists in the workbook namespace, the Add method will fail.
SlicerCacheTypeSlicerCacheType 可选Optional XlSlicerCacheTypeXlSlicerCacheType 指定切片器或切片器缓存的类型。Designates the type of slicer or slicer cache.

返回值Return value

SlicerCacheSlicerCache

示例Example

下面的代码示例添加基于 Customer Geography OLAP 层次结构的切片器缓存。The following code example adds a slicer cache based on the Customer Geography OLAP hierarchy.

 ActiveWorkbook.SlicerCaches.Add(ActiveCell.PivotTable, _ 
 "[Customer].[Customer Geography]")

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