代码之家  ›  专栏  ›  技术社区  ›  RobExcel

检索数据表中切片器的设置

  •  0
  • RobExcel  · 技术社区  · 9 年前

    我甚至不确定这是否可行。但我使用的是一个很大的数据表,主要由切片器控制。当我提取此数据表时,我希望在标题中包含切片器的设置和提取日期/时间(作为切片器正确设置的额外确认,当然还有提取数据的时间点)。

    谷歌不知道答案,由于我的谷歌浏览器往往很强大,我来这里寻求建议。

    1 回复  |  直到 8 年前
        1
  •  0
  •   RobExcel    9 年前

    啊,找到了。

    使用以下代码创建了一个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
    
    推荐文章