看看这样能满足要求不 Sub Macro2() Dim pntAddress As Range Application.ScreenUpdating = False PIcnt = ActiveSheet.PivotTables("数据透视表2").PivotFields("姓名").PivotItems.Count With ActiveSheet.PivotTables("数据透视表2").PivotFields("姓名") For i = 2 To PIcnt .PivotItems(1).Visible = True .PivotItems(i).Visible = False Next i Set pntAddress = Range("F1", "H" & getlastusedrow(Range("F1"))) ActiveSheet.PageSetup.PrintArea = pntAddress.Address ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True For j = 2 To PIcnt - 1 .PivotItems(j).Visible = True .PivotItems(j - 1).Visible = False Set pntAddress = Range("F1", "H" & getlastusedrow(Range("F1"))) ActiveSheet.PageSetup.PrintArea = pntAddress.Address ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True Next j End With Application.ScreenUpdating = True End Sub Function getlastusedrow(rg As Range) As Long Dim lmaxrows As Long lmaxrows = ThisWorkbook.Worksheets(1).Rows.Count If IsEmpty(rg.Parent.Cells(lmaxrows, rg.Column)) Then getlastusedrow = rg.Parent.Cells(lmaxrows, rg.Column).End(xlUp).Row Else getlastusedrow = rg.Parent.Cells(lmaxrows, rg.Column).Row End If End Function
[此贴子已经被作者于2007-9-19 10:18:30编辑过] |