SlicerCaches.Add method (Excel)

Adds a new SlicerCache object to the collection.

Syntax

expression.Add (Source, SourceField, Name, SlicerCacheType)

expression A variable that represents a SlicerCaches object.

Parameters

Name Required/Optional Data type Description
Source Required Variant The data source that the new SlicerCache object will be based on. The argument passed to the Source parameter can be a WorkbookConnection object, a PivotTable object, or a string.

If a PivotTable object is passed, the associated PivotCache object is used as the data source. 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.
SourceField Required Variant The name of the field in the data source to filter by. 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).

For OLAP data sources, use the MDX unique name of the hierarchy that the SlicerCache is based on. You can also specify a level of the OLAP hierarchy, and Excel will use the corresponding hierarchy.
Name Optional Variant The name that Excel uses to reference the slicer cache (the value of the SlicerCache.Name property). If omitted, Excel will generate a name.

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 "_").

If required to make the name unique in the workbook namespace, Excel adds an integer to the end of the generated name. If you specify a name that already exists in the workbook namespace, the Add method will fail.
SlicerCacheType Optional XlSlicerCacheType Designates the type of slicer or slicer cache.

Return value

SlicerCache

Example

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

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.