I wi sh, чтобы ограничить выбор пользователя слайсера одним. Пробовал этот код, но он не работал. Любая помощь будет принята с благодарностью.
Private Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, _
ByVal Target As PivotTable)
'--when pivot update event triggered, checks whether a specified slicer
' has more than one item selected.
' If so, user is warned and optionally the last action can be undone
Dim bSlicerIsConnected As Boolean
Dim pvt As PivotTable
Dim slc As SlicerCache
Dim sLastUndoStackItem As String
'--modify this to match your slicer's name
Const sSLICER_NAME As String = "SlicerName"
sLastUndoStackItem = Application.CommandBars("Standard").FindControl(ID:=128).List(1)
'--validate event was triggered by slicer or filter, not other pivot operation
Select Case sLastUndoStackItem
Case "Slicer Operation", "Filter"
'continue
Case Else
'do nothing and exit
GoTo ExitProc
End Select
'--validate specified slicer exists
On Error Resume Next
Set slc = SlicerCaches(sSLICER_NAME)
On Error GoTo 0
If slc Is Nothing Then
GoTo ExitProc
End If
'--validate pvt that triggered event is connected to specified slicer
For Each pvt In slc.PivotTables
If pvt.Name = Target.Name Then
bSlicerIsConnected = True
Exit For
End If
Next pvt
'--test how many items selected and take action if more than one
If bSlicerIsConnected Then
If slc.VisibleSlicerItems.Count > 1 Then
'--option a: only warn user
'MsgBox "Only one item may be selected" & vbCr _
' & "Please undo last selection."
'--option b: warn user and undo
MsgBox "Only one item may be selected"
With Application
.EnableEvents = False
.Undo
End With
End If
End If
ExitProc:
Application.EnableEvents = True
End Sub