0
何らかの理由で名前付き範囲を試しましたが、マクロを実行した後に式が名前付き範囲内で自動的に変化し続けます。だから私はマクロ自体の範囲を設定しようとしました。 私は、スライサーを見て2枚のシートをPDFとして保存するマクロを書いています。第2のタブは、スライサーが変化するたびにエリア範囲が変化するピボットを有する。誰かが私を助けて、これがPDFに動的に印刷されるようにすることはできますか?ダイナミックピボットを印刷領域に設定する
Sub Loopexport()
Dim ws2 As Worksheet
Dim PT As PivotTable
'Hide non-printable sheets
Sheets("Overview").Visible = False
Sheets("KPExport").Visible = False
Set ws2 = Sheets("Id CUps")
Set PT = ws2.PivotTables(1)
'Set print areas
Sheets("Stats").PageSetup.PrintArea = "$A$1:$M$39"
ws2.PageSetup.PrintArea = PT.TableRange2 'this is where I am receiving the type mismatch. and the = "My named range" kept changing automatically at the end.
With Sheets("Id CUps").Columns("D:D")
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'Print Regions
'Export N1
ActiveWorkbook.SlicerCaches("Slicer_Dt").VisibleSlicerItemsList = Array("[UserID].[Dept].&[N1]")
ChDir ("C:\My Docs\A\B\Export")
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\My Docs\A\B\Export\N1 - " & Format(Now(), "YYYY") & "M" & Format(Now(), "MM")
End Sub