Class Slicer (Excel VBA)

The class Slicer represents a slicer in a workbook.

The main procedures of class Slicer are Copy, Delete and Slicers.Add


To use a Slicer class variable it first needs to be instantiated, for example

Dim slc as Slicer
Set slc = ActiveWorkbook.ActiveSlicer

The following procedures can be used to set variables of type Slicer: Slicers.Item, Slicers.Add, Workbook.ActiveSlicer, ListObject.Slicers, PivotTable.Slicers and SlicerCache.Slicers

For Each

Here is an example of processing the Slicer items in a collection.

Dim slc As Slicer
For Each slc In Application.Slicers
Next slc


These are the main methods of the Slicer class

Copy - Copies the specified slicer to the clipboard.


Delete - Deletes the slicer and removes it from the associated Slicers collection.


Slicers.Add - Creates a new slicer and returns a Slicer object.

Sub CreateNewSlicer() 
 ActiveWorkbook.SlicerCaches.Add("Adventure Works", _ 
 "[Customer].[Customer Geography]").Slicers.Add ActiveSheet, _ 
 "[Customer].[Customer Geography].[Country]", "Country 1", "Country", _ 
 252, 522, 144, 216) 
End Sub

Other Methods

Cut - Cuts the specified slicer and copies it to the clipboard.


ActiveItem returns a SlicerItem object that represents the slicer button that is currently in focus for the specified slicer.

Caption returns or sets the caption of the specified slicer.

ColumnWidth returns or sets the width, in points, of each column in the slicer.

DisableMoveResizeUI returns or sets whether the specified slicer can be moved or resized by using the user interface.

DisplayHeader returns or sets whether the header that displays the slicer Caption property is visible.

Height returns or sets the height of the specified slicer, in points.

Left returns or sets the horizontal position of the specified slicer, in points, relative to the upper-left corner of cell A1 on a worksheet.

Locked returns or sets whether the specified slicer can be modified when the sheet that contains it is protected.

Name returns or sets the name of the specified slicer.

NumberOfColumns returns or sets the number of columns in the specified slicer.

Parent returns the Worksheet object that represents the sheet that contains the slicer. Read-only.

RowHeight returns or sets the height, in points, of each row in the specified slicer.

Shape returns the Shape object associated with the specified slicer.

SlicerCache returns the SlicerCache object associated with the slicer.

SlicerCacheLevel returns the SlicerCacheLevel object associated with the slicer.

SlicerCacheType returns the type of the slicer cache: slicer (xlSlicer) or timeline (xlTimeline) .

Style returns or sets the style currently applied to the specified slicer. Read/write.

TimelineViewState the timeline-specific state of the slicer.

Top returns or sets the vertical position of the specified slicer, in points, relative to the upper-left corner of cell A1 on a worksheet.

Width returns or sets the width of the specified slicer, in points.

Slicers.Count returns the number of objects in the collection.

Slicers.Item returns a Slicer object from the collection.

Slicers.Parent returns the parent SlicerCache object for the specified Slicers collection. Read-only.