MACRO运行切片器并将过滤后的数据打印成pdf

时间:2017-12-21 17:56:16

标签: excel-vba pdf vba excel

我是宏的新手,我需要编写一个将数据打印到通过切片器在页面上生成的pdf。

我有这个宏,它在运行时会中断。

Public Sub myMacro()
Dim sC As SlicerCache
Set sC = ActiveWorkbook.SlicerCaches("Slicer_Name")

这提醒用户只选择第一个切片器项

If sC.VisibleSlicerItems.Count <> 1 Or sC.SlicerItems(1).Selected = False Then
      MsgBox "Please Only Select Store-Number 1"
      Exit Sub
   End If

For i = 1 To sC.SlicerItems.Count

不要清除过滤器,因为它会导致选择所有物品(sC.ClearManualFilter)

sC.SlicerItems(i).Selected = True
If i <> 1 Then sC.SlicerItems(i - 1).Selected = False


'Debug.Print sI.Name
'add export to PDF code here
With ActiveSheet.PageSetup

.PrintArea = ActiveSheet.Range("A1:u61" & lastRow).Address

.FitToPagesWide = 1
.FitToPagesTall = 1

End With

ActiveSheet.Range("d5") = sC.SlicerItems(i).Name

这将打印到C目录,根据需要更改路径

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\vitienkr\Desktop\Board Pack\test.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False_

Next

End Sub

此部分以黄色突出显示:

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\vitienkr\Desktop\Board Pack\test.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False_

我真的不知道如何修复它。拜托,有人可以帮助我吗?

0 个答案:

没有答案