考虑到我在SlicerCaches中选择了所有的切片器,这段代码仍然没有选择正确的切片器:
Dim sli As SlicerItem
With ActiveWorkbook.SlicerCaches("Slicer_Sub_Function__Div_5")
For Each sli In ActiveWorkbook.SlicerCaches("Slicer_Sub_Function__Div_5").SlicerItems
If Not sli.Name = "America" Then sli.Selected = False
Next
End With
我希望除了美国,其他国家不应该被选中有人能帮忙吗?
应该这样做:
Dim sli As SlicerItem
With ActiveWorkbook.SlicerCaches("Slicer_Sub_Function__Div_5")
.SlicerItems("America").Selected = True 'show the item of interest
For Each sli In .SlicerItems
If sli.Name <> "America" Then sli.Selected = False
Next
End With
…只要您不使用数据模型作为PT的源(即。它只是基于一个范围)