在 data-sheet 中检索切片器的设置
Retrieving settings of Slicers in data-sheet
我什至不确定这是否可行。但我使用的是一个相当庞大的数据表,主要由切片器控制。当我提取此数据表时,我希望在 header 中包含切片器的设置和提取的 date/time(作为对切片器正确设置的额外确认,当然还有一点提取数据的时间)。
Google不知道答案,我的google-fu偏强,特来求教
这可能吗?最好在 VBA.
中进行
啊找到了。
使用以下代码创建了一个 PublicFunction,它将显示选定的切片器值。
Public Function GetSelectedSlicerItems(SlicerName As String) As String
Dim oSc As SlicerCache
Dim oSi As SlicerItem
Dim lCt As Long
On Error Resume Next
Application.Volatile
Set oSc = ThisWorkbook.SlicerCaches(SlicerName)
If Not oSc Is Nothing Then
For Each oSi In oSc.SlicerItems
If oSi.Selected Then
GetSelectedSlicerItems = GetSelectedSlicerItems & oSi.Name & ", "
lCt = lCt + 1
ElseIf oSi.HasData = False Then
lCt = lCt + 1
End If
Next
If Len(GetSelectedSlicerItems) > 0 Then
If lCt = oSc.SlicerItems.Count Then
GetSelectedSlicerItems = "All"
Else
GetSelectedSlicerItems = Left(GetSelectedSlicerItems, Len(GetSelectedSlicerItems) - 2)
End If
Else
GetSelectedSlicerItems = "No items selected"
End If
Else
GetSelectedSlicerItems = "No slicer with name '" & SlicerName & "' was found"
End If
End Function
我什至不确定这是否可行。但我使用的是一个相当庞大的数据表,主要由切片器控制。当我提取此数据表时,我希望在 header 中包含切片器的设置和提取的 date/time(作为对切片器正确设置的额外确认,当然还有一点提取数据的时间)。
Google不知道答案,我的google-fu偏强,特来求教
这可能吗?最好在 VBA.
中进行啊找到了。
使用以下代码创建了一个 PublicFunction,它将显示选定的切片器值。
Public Function GetSelectedSlicerItems(SlicerName As String) As String
Dim oSc As SlicerCache
Dim oSi As SlicerItem
Dim lCt As Long
On Error Resume Next
Application.Volatile
Set oSc = ThisWorkbook.SlicerCaches(SlicerName)
If Not oSc Is Nothing Then
For Each oSi In oSc.SlicerItems
If oSi.Selected Then
GetSelectedSlicerItems = GetSelectedSlicerItems & oSi.Name & ", "
lCt = lCt + 1
ElseIf oSi.HasData = False Then
lCt = lCt + 1
End If
Next
If Len(GetSelectedSlicerItems) > 0 Then
If lCt = oSc.SlicerItems.Count Then
GetSelectedSlicerItems = "All"
Else
GetSelectedSlicerItems = Left(GetSelectedSlicerItems, Len(GetSelectedSlicerItems) - 2)
End If
Else
GetSelectedSlicerItems = "No items selected"
End If
Else
GetSelectedSlicerItems = "No slicer with name '" & SlicerName & "' was found"
End If
End Function