我写了一个宏,将变量名放入字典(称为Occs),然后尝试在切片器中选择那些名称。似乎我错了一行:
Sub Macro4()
Dim Occs As New Dictionary
Occs.Add "001", "001"
Occs.Add "002", "002"
Dim sC As SlicerCache
Dim sI As SlicerItem
Dim index As Integer
Set sC = ActiveWorkbook.SlicerCaches("Slicer_Occupation_Code1")
sC.ClearManualFilter
For index = 1 To sC.SlicerCacheLevels.Count
For Each sI In sC.SlicerCacheLevels(index).SlicerItems
sI.Selected = Occs.Exists(sI.Caption)
Next sI
Next index
End Sub
如果在Occs词典中,则应在实际选择项目的行上显示“ 1004:应用程序定义的错误或对象定义的错误”:
sI.Selected = Occs.Exists(sI.Caption)
这行应该改为什么?任何帮助表示赞赏。