问题描述
我在迭代几个 Power Pivot 切片器以执行几个功能时采用的代码出现 1004 个错误。
All VBA Slicer Combinations video
我对 VBA 还很陌生,所以我可以使用一些指导。
我正在尝试自动生成每月演示文稿,该演示文稿要求我讨论为两个切片器的组合旋转的相同 3 个图形。允许我将这些图形复制到 PowerPoint 的部分工作正常,因此我简化了下面的代码。在我遇到错误的区域周围放置 *'s
Sub DoAllCombinations()
Dim sc1 As SlicerCache
Dim sc2 As SlicerCache
Dim SI As SlicerItem
Dim cella As Range
Dim cellb As Range
' These names come from Slicer Settings dialog Box
Set sc1 = ThisWorkbook.SlicerCaches("Slicer1_here") 'input
Set sc2 = ThisWorkbook.SlicerCaches("Slicer2_here") 'input
sc1.ClearallFilters
sc2.ClearallFilters
Ctr = 1
' off to the right,build 2 Static lists of all slicer items
NextCol = ActiveSheet.UsedRange.Columns.Count + 20
RememberCol = NextCol
NextRow = 1
**For Each SI In sc1.SlicerItems**
Cells(NextRow,NextCol).Value = SI.Caption
NextRow = NextRow + 1
Next SI
LastRow = NextRow - 1
Cells(1,NextCol).Resize(LastRow,1).Name = "SlicerItems1"
NextRow = 1
NextCol = NextCol + 1
**For Each SI In sc2.SlicerItems**
Cells(NextRow,1).Name = "SlicerItems2"
' This will speed up the code
Application.ScreenUpdating = False
' Loop Through all Slicer items,choosing just the one item
' Have to do it this way as there is no index built into the slicer object
For Each cella In Range("SlicerItems1")
sc1.ClearallFilters
**For Each SI In sc1.SlicerItems**
If SI.Caption = cell1.Value Then
**SI.Selected = True**
Else
**SI.Selected = False**
End If
Next SI
'////////insert summary table to powerpoint//////
' Loop Through all Slicer items,choosing just the one item
For Each cellb In Range("SlicerItems2")
sc2.ClearallFilters
**For Each SI In sc2.SlicerItems**
If SI.Caption = cellb.Value Then
**SI.Selected = True**
Else
SI.Selected = False
End If
Next SI
'/////////// Function :print all graphs for all items in cellb here//////////
Next cellb
Next cella
'Clear out the Static Lists
Cells(1,RememberCol).Resize(1,2).EntireColumn.Clear
Application.ScreenUpdating = True
MsgBox (Ctr - 1) & "custom message"
End Sub
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)