0
我一直在使用Excel和VBA,并且试图找出如何从切片器中取消选择各个字段并仅选择少量字段。 我尝试读取切片器Cache,然后遍历切片器中的各种项目。我能够读取切片机内物品的值,但我无法取消选择它们。它不断抛出错误代码为1004的“应用程序定义或对象定义的错误”。无法将VBA切片器选定的属性值设置为False
我在分享我遇到困难的代码段。
Sub SelectFiscalWeeks()
Dim slcCache As SlicerCache
Dim slcItem As SlicerItem
FalseVar = False
Application.StatusBar = "Filtering out last 13 Week's Data"
Set slcCache = ThisWorkbook.SlicerCaches("Slicer_Date.Fiscal_Week")
slcCache.ClearManualFilter
For Index = 1 To slcCache.SlicerCacheLevels.Count
Worksheets("A").Cells(Index + 1, "N").Value = Index
j = 0
For Each slcItem In slcCache.SlicerCacheLevels(Index).SlicerItems
Worksheets("A").Cells(j + 1, "P").Value = slcItem.Name
j = j + 1
slcItem.Selected = FalseVar
Next
Next
'Set slcCache.VisibleSlicerItems = Array("[DT].[FW].&[201701]")
Set slcCache = Nothing
Application.StatusBar = False
End Sub
在上面的代码,我能够通过使用slcItem.Name阅读切片项目名称,但我无法既可以执行下面的语句:
slcItem.Selected = FalseVar
Set slcCache.VisibleSlicerItems = Array("[DT].[FW].&[201701]")
执行这些语句抛出了错误“应用程序定义或对象定义的错误”与错误代码1004.
我一直在尝试调试超过一个小时,但无法找出原因。这可能是一些基本的东西,但是你能帮我确定我的代码可能有什么问题吗?