迭代vba中的excel切片器选项

时间:2013-03-29 13:01:42

标签: excel-vba pivot vba excel

我有一个数据透视图,它有一个连接到它的切片器(和一个输入器)。我想逐个遍历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

1 个答案:

答案 0 :(得分:0)

问题已解决,请参阅问题下的评论。