Public Sub Hide_or_Unhide_Slicers()
Dim clickedButton As Button
Dim slCache As SlicerCache
Dim sl As Slicer
Dim slicerSettingsWs As Worksheet
Dim r As Long
Set slicerSettingsWs = ThisWorkbook.Worksheets("Slicer Settings")
Set clickedButton = ActiveSheet.Buttons(Application.Caller)
If clickedButton.Caption = "Hide" Then
With slicerSettingsWs
For r = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row
Set slCache = ThisWorkbook.SlicerCaches(.Cells(r, 1).Value)
Set sl = slCache.Slicers(.Cells(r, 2).Value)
sl.Width = 0
sl.Height = 0
'Select a cell on this slicer's worksheet to unselect the slicer itself
sl.Parent.Select
sl.Parent.Range("A1").Select
Next
End With
clickedButton.Caption = "Unhide"
ElseIf clickedButton.Caption = "Unhide" Then
With slicerSettingsWs
For r = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row
Set slCache = ThisWorkbook.SlicerCaches(.Cells(r, 1).Value)
Set sl = slCache.Slicers(.Cells(r, 2).Value)
sl.Width = .Cells(r, 3).Value
sl.Height = .Cells(r, 4).Value
'Select a cell on this slicer's worksheet to unselect the slicer itself
sl.Parent.Select
sl.Parent.Range("A1").Select
Next
End With
clickedButton.Caption = "Hide"
End If
End Sub
Public Sub Save_Slicers()
Dim slicerSettingsWs As Worksheet
Dim slCache As SlicerCache
Dim i As Long, r As Long
With ThisWorkbook
Set slicerSettingsWs = Nothing
On Error Resume Next
Set slicerSettingsWs = .Worksheets("Slicer Settings")
On Error GoTo 0
If slicerSettingsWs Is Nothing Then
Application.ScreenUpdating = False
Set slicerSettingsWs = .Worksheets.Add(After:=.Worksheets(.Worksheets.Count))
Application.ScreenUpdating = True
slicerSettingsWs.Name = "Slicer Settings"
End If
End With
slicerSettingsWs.Visible = xlSheetVeryHidden
slicerSettingsWs.Cells.ClearContents
r = 0
For Each slCache In ThisWorkbook.SlicerCaches
For i = 1 To slCache.Slicers.Count
With slicerSettingsWs
r = r + 1
.Cells(r, 1).Value = slCache.Name
.Cells(r, 2).Value = slCache.Slicers(i).Name
.Cells(r, 3).Value = slCache.Slicers(i).Width
.Cells(r, 4).Value = slCache.Slicers(i).Height
End With
Next
Next
End Sub