我有一个透视图,它有一个切片器(和一个子切片器)连接到它。我想一个一个地遍历 vba 中的所有切片器选项,这将返回一个输出(这将在图表上显示一些东西,而不仅仅是一个空的图表区域)。
我怎么能在 VBA 中做到这一点?
编辑 我正在尝试使用此代码遍历切片器列表,但切片器选择永远不会改变:
For Each Si In ActiveWorkbook.SlicerCaches("Slicer_Afsnit").SlicerItems
If (Si.HasData) Then
Si.Selected = True '<<<<<<< this line here does nothing apparently!, the graphs stay the same always, when copied to new documents
Set WDDoc = WDApp.Documents.Add
For iCht = 1 To ActiveSheet.ChartObjects.Count
' copy chart as a picture
ActiveSheet.ChartObjects(iCht).Chart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
WDApp.Selection.Range.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False
WDApp.Selection.MoveEnd wdStory
WDApp.Selection.Move
Next
WDDoc.SaveAs (ThisWorkbook.Path & "\" & FileFriendly(Si.Name) & ".doc")
WDDoc.Close ' close the document
'get mail for the department
depmail = Cells(ActiveWorkbook.Sheets("Enheder").UsedRange.Find(Si.Name).Row, 2).value
If Not (depmail = "") Then
X = SendMail(depmail, "ugentlig audit", "Resultater for " & Si.Name, ThisWorkbook.Path & "\" & Si.Name & ".doc")
End If
End If