Microsoft Office Tutorials and References
In Depth Information
20.12.2.5 PrintPTs procedure
' Add item to list box
lstPTs.AddItem PT.Name & " ( in " & _
sSheets(cPTs) & ")"
Next
Next
End Sub
20.12.2.5 PrintPTs procedure
The main printing procedure is shown in Example 20-10 . Note that we have been careful to deal
with two special cases. First, there may not be any pivot tables in the workbook. Second, the user
may hit the Print button without selecting any pivot tables in the list box. Note also that list boxes
are 0-based, meaning that the first item is item 0. However, our arrays are 1-based (the first item is
item 1), so we must take this into account when we move from a selection to an array member; to
wit, selection i corresponds to array index i+1 .
Example 20-10. The PrintSelectedPTs Procedure
Sub PrintSelectedPTs()
' Print the selected pivot tables in lstPTs
Dim i As Integer
Dim bNoneSelected As Boolean
bNoneSelected = True
If cPTs = 0 Then
MsgBox "No pivot tables in this workbook.", _
vbExclamation
Exit Sub
Else
For i = 0 To lstPTs.ListCount - 1
If lstPTs.Selected(i) Then
bNoneSelected = False
' List box is 0-based, arrays are 1-based
Worksheets(sSheets(i + 1)). _
PivotTables(sPTNames(i + 1)). _
TableRange2.PrintOut
End If
Next
End If
If bNoneSelected Then
MsgBox "No pivot tables have been selected.", _
vbExclamation
End If
End Sub
 
Search JabSto ::




Custom Search