|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
楼主的透视表是2007中做的,给个参考代码先:
Sub 测试()
On Error Resume Next
c = MsgBox("开始打印吗?", vbOKCancel + vbDefaultButton2)
If c = vbCancel Then Exit Sub
Dim pntAddress As Range
Dim tname As String
'Application.ScreenUpdating=False '关闭屏幕刷新
tname = "数据透视表2"
With ActiveSheet.PivotTables(tname).PivotFields("姓名")
PIcnt = .PivotItems.Count
J = 1: JJ = 1
For JJ = 1 To PIcnt
.PivotItems.Item(PIcnt).Visible = True
J = 1
For J = 1 To PIcnt
If JJ <> J Or .PivotItems(J).Name = "(空白)" Then
.PivotItems.Item(J).Visible = False
Else
.PivotItems.Item(J).Visible = True
End If
Application.StatusBar = J & " - " & JJ & "/" & PIcnt
Next J
ActiveSheet.PivotTables(tname).PivotSelect "", xlDataAndLabel, True
ActiveSheet.PageSetup.PrintArea = Selection.Address
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Next JJ
End With
Application.ScreenUpdating = True '打开屏幕刷新
End Sub |
|