-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod_off_ExcelPivotTables (from acc).bas
executable file
·658 lines (585 loc) · 22 KB
/
mod_off_ExcelPivotTables (from acc).bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
Attribute VB_Name = "mod_off_ExcelPivotTables"
' mod_off_ExcelPivotTables
' miscellaneous Pivot Table manipulation routines
' 130912.AMG converted from mod_exc_PivotTables to work from any office programme
' 130910.AMG added error handling
' 130909.AMG refactored more functions in for simpler calling code, and added formatting features
' 130906.AMG created
' NB if this project is being used outside Excel it requires REFERENCES to execute:
' Microsoft Office Excel 12 c:\Program Files\Microsoft Office\Office12\ExCEL.EXE
Option Explicit
' error handling tag
Const cStrModuleName As String = "mod_off_ExcelPivotTables"
Public Enum eNumberFormat
[_First] = 1
General = 1
DecimalNumber
IntegerNumber
CurrencyValue
[_Last]
End Enum
Function FirstWorksheetWholeTableAddress _
(wbk As Excel.Workbook _
) As String
FirstWorksheetWholeTableAddress = "'" & wbk.Worksheets(1).Name & "'!" & wbk.Worksheets(1).UsedRange.Address
End Function
Function PivotCacheAdd _
(wbk As Excel.Workbook _
, strDataRange As String _
) As Excel.PivotCache
''' standard procedure error handler begin initialise 130813.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject, strProcedureName As String
strProcedureName = "PivotCacheAdd"
strErrorObject = CStr(strDataRange)
''' standard procedure error handler end initialise '''
' Create a PivotCache for as many PivotTables as required
' Don't bother declaring internally as the function is just a 1-liner
' Dim cch As Excel.PivotCache
Set PivotCacheAdd = wbk.PivotCaches.Add( _
SourceType:=xlDatabase, _
SourceData:=strDataRange)
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & strProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
Function PivotTableAddOnNewSheet _
(ByRef wbk As Excel.Workbook _
, ByRef cch As Excel.PivotCache _
, ByVal strPivotSheetName As String _
, ByVal lIndex As Long _
, Optional lRow As Long = 3 _
) As Excel.PivotTable
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotTableAddOnNewSheet"
strErrorObject = strPivotSheetName
''' standard procedure error handler end initialise '''
Dim sht As Worksheet
Dim pvt As PivotTable
' create the sheet and the table
Set sht = wbk.Sheets.Add
sht.Name = strPivotSheetName
' position the sheet
' if index parameter is less then 1 then it is relative to LAST existing worksheet...
Dim lAbsolute As Long
If lIndex > 0 Then
lAbsolute = lIndex
Else
lAbsolute = wbk.Worksheets.Count + lIndex
End If
sht.Move after:=wbk.Worksheets(lAbsolute)
' create pivot
Set pvt = cch.CreatePivotTable( _
TableDestination:=wbk.Worksheets(strPivotSheetName).Cells(lRow, 1), _
tablename:=strPivotSheetName)
' return object
Set PivotTableAddOnNewSheet = pvt
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
Function PivotHideValue _
(pvt As Object _
, strFieldName As String _
, strCheckValue As String _
) As Boolean
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotHideValue"
strErrorObject = "Pivot: " & pvt.Name & " Field: " & strFieldName & " Value: " & strCheckValue
''' standard procedure error handler end initialise '''
Dim i As Integer
For i = 1 To pvt.PivotFields(strFieldName).PivotItems.Count
If strCheckValue = pvt.PivotFields(strFieldName).PivotItems(i).Name Then
pvt.PivotFields(strFieldName).PivotItems(strCheckValue).Visible = False
Exit Function
End If
Next i
' if no such value is found, simply exit (rather than throw an error)
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
Function PivotHideAllValuesExcept _
(pvt As PivotTable _
, strFieldName As String _
, strCheckValue As String _
)
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotHideAllValuesExcept"
strErrorObject = "Pivot: " & pvt.Name & " Fields: " & strFieldName & " Value: " & strCheckValue
''' standard procedure error handler end initialise '''
' Dim i As Integer
' For i = 1 To pvt.PivotFields(strFieldName).PivotItems.Count
' If strCheckValue = pvt.PivotFields(strFieldName).PivotItems(i).Name Then
' pvt.PivotFields(strFieldName).PivotItems(strCheckValue).Visible = False
Dim strFullCheck, strRootError As String
Dim pi As PivotItem
Const cStrDelim As String = ","
' strCheckValues is a comma delimited list, so make it easy to search by topping and tailing it
strFullCheck = cStrDelim & strCheckValue & cStrDelim
strRootError = strErrorObject
For Each pi In pvt.PivotFields(strFieldName).PivotItems
If InStr(strFullCheck, cStrDelim & pi.Name & cStrDelim) > 0 Then
strErrorObject = strRootError & " setting " & pi.Name & " visible"
pi.Visible = True
Else
strErrorObject = strRootError & " setting " & pi.Name & " invisible"
pi.Visible = False
End If
Next
' Next i
' if no such value is found, simply exit (rather than throw an error)
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
Function PivotFieldFilter _
(fld As PivotField _
, Value _
) As Boolean
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotFieldFilter"
strErrorObject = "PivotField: " & fld.Name & " Value: " & CStr(Value)
''' standard procedure error handler end initialise '''
Excel.Application.ScreenUpdating = False
With fld
If .Orientation = xlPageField Then
.CurrentPage = Value
ElseIf .Orientation = xlRowField Or .Orientation = xlColumnField Then
Dim i As Long
On Error Resume Next ' Needed to avoid getting errors when manipulating fields that were deleted from the data source.
' Set first item to Visible to avoid getting no visible items while working
.PivotItems(1).Visible = True
For i = 2 To fld.PivotItems.Count
If .PivotItems(i).Name = Value Then _
.PivotItems(i).Visible = True Else _
.PivotItems(i).Visible = False
Next i
If .PivotItems(1).Name = Value Then _
.PivotItems(1).Visible = True Else _
.PivotItems(1).Visible = False
End If
End With
Excel.Application.ScreenUpdating = True
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
'Function PivotFieldSetAsFirstRow _
'(fld As PivotField _
')
'''' standard procedure error handler begin initialise 130910.AMG '''
'ErrorAlerts False
'On Error GoTo ErrorHandler
'Dim strErrorObject As String
'Const cStrProcedureName As String = "PivotFieldFilter"
'strErrorObject = "PivotField: " & fld.Name & " Value: " & CStr(Value)
'''' standard procedure error handler end initialise '''
'
' Excel.Application.ScreenUpdating = False
' With fld
' .Orientation = xlRowField
' .Position = 1
' End With
' Excel.Application.ScreenUpdating = True
'
'''' standard procedure error handler begin terminate 130910.AMG '''
'Proc_Exit:
'ErrorAlerts True
'Exit Function
'ErrorHandler:
'ErrorAlerts True
'LogException "ERROR", "Trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
'strErrorObject & ") - " & "Error " & Err.Number & vbCrLf & " - """ & Err.Description & """"
'Err.Raise (Err.Number)
'Resume Proc_Exit
'''' standard procedure error handler end terminate '''
'End Function
Function PivotSetFieldAsFirstRow _
(pvt As PivotTable _
, strFieldName As String _
)
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotSetFieldAsFirstRow"
strErrorObject = "Pivot: " & pvt.Name & " Field: " & strFieldName
''' standard procedure error handler end initialise '''
Excel.Application.ScreenUpdating = False
With pvt.PivotFields(strFieldName)
.Orientation = xlRowField
.Position = 1
End With
Excel.Application.ScreenUpdating = True
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
Function PivotRowFieldFormat _
(ByRef pvt As PivotTable _
, ByVal strFieldName As String _
, ByVal lFormat As eNumberFormat _
)
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotRowFieldFormat"
strErrorObject = "Pivot: " & pvt.Name & " Field: " & strFieldName
''' standard procedure error handler end initialise '''
Excel.Application.ScreenUpdating = False
Dim rng As Range
Set rng = pvt.PivotFields(strFieldName).DataRange
Select Case lFormat
Case eNumberFormat.General:
rng.NumberFormat = "General"
Case eNumberFormat.DecimalNumber:
rng.NumberFormat = "0.00"
Case eNumberFormat.IntegerNumber:
rng.NumberFormat = "0"
Case eNumberFormat.CurrencyValue:
rng.NumberFormat = "£#,##0"
Case Else:
End Select
Excel.Application.ScreenUpdating = True
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
' It was NOT valid to set number format for a rowfield :(
' "You can set the NumberFormat property only for a data field"
' quote > http://msdn.microsoft.com/en-us/library/office/bb237338(v=office.12).aspx
' so set it after the pivot is complete
'Function PivotSetFieldAsFirstRow _
' (pvt As PivotTable _
' , strFieldName As String _
' , Optional ByVal lFormat As eNumberFormat _
' )
' Excel.Application.ScreenUpdating = False
' With pvt.PivotFields(strFieldName)
' .Orientation = xlRowField
' .Position = 1
' If Not IsMissing(lFormat) Then
' Select Case lFormat
' Case eNumberFormat.General:
' .NumberFormat = "General"
' Case eNumberFormat.DecimalNumber:
' .NumberFormat = "0.00"
' Case eNumberFormat.IntegerNumber:
' .NumberFormat = "0"
' Case eNumberFormat.CurrencyValue:
' .NumberFormat = "£#,##0"
' Case Else:
' End Select
' End If
' End With
' Excel.Application.ScreenUpdating = True
'End Function
Function PivotSetFieldAsTotal _
(ByRef pvt As PivotTable _
, ByVal strFieldName As String _
, Optional ByVal strCaption As String _
, Optional lFormat As eNumberFormat _
)
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotSetFieldAsTotal"
strErrorObject = "Pivot: " & pvt.Name & " Field: " & strFieldName
''' standard procedure error handler end initialise '''
Excel.Application.ScreenUpdating = False
With pvt.PivotFields(strFieldName)
.Orientation = xlDataField
.Function = xlSum
' Summing the field changes the caption, so either set it as specified,
' or simply revert to the original field name
If IsMissing(strCaption) Then
.Caption = strFieldName
Else
.Caption = strCaption
End If
If Not IsMissing(lFormat) Then
Select Case lFormat
Case eNumberFormat.General:
.NumberFormat = "General"
Case eNumberFormat.DecimalNumber:
.NumberFormat = "0.00"
Case eNumberFormat.IntegerNumber:
.NumberFormat = "0"
Case eNumberFormat.CurrencyValue:
.NumberFormat = "£#,##0"
Case Else:
End Select
End If
End With
Excel.Application.ScreenUpdating = True
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
Function PivotShowSubtotalsOnFields _
(pvt As PivotTable _
, strFieldNames As String _
)
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotShowSubtotalsOnFields"
strErrorObject = "Pivot: " & pvt.Name & " Fields: " & strFieldNames
''' standard procedure error handler end initialise '''
' accepts a comma-delimited list of Field Names
Const cStrDelim As String = ","
' all fields NOT in list will have their subtotals turned off
' e.g.
' PivotShowSubtotalsOnFields pvt, "Phase,Class"
Excel.Application.ScreenUpdating = False
Dim fld As PivotField
' Make the delimited list easy to search by topping and tailing it
Dim strDelimitedList, strNameWithDelims As String
strDelimitedList = cStrDelim & strFieldNames & cStrDelim
For Each fld In pvt.PivotFields
strNameWithDelims = cStrDelim & fld.Name & cStrDelim
If InStr(1, strNameWithDelims, strDelimitedList, vbTextCompare) Then
fld.Subtotals(1) = True
Else
fld.Subtotals(1) = False
End If
Next fld
Excel.Application.ScreenUpdating = True
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
Function PivotColumnFormat _
(pvt As PivotTable _
, strFieldName As String _
, Optional dWidth As Double = 0 _
, Optional bWrap As Boolean = False _
)
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotColumnFormat"
strErrorObject = "Pivot: " & pvt.Name & " Field: " & strFieldName
''' standard procedure error handler end initialise '''
' credit > useful visual reference for accessing parts of pivot table
' and how to use the valuable intersect
' http://peltiertech.com/WordPress/referencing-pivot-table-ranges-in-vba/
Dim rng As Range
Set rng = pvt.PivotFields(strFieldName).DataRange
If dWidth <> 0 Then
rng.ColumnWidth = dWidth
End If
If bWrap Then
rng.WrapText = True
End If
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
Function PivotColumnsAutoFit _
(pvt As PivotTable _
, Optional strFieldNames As String _
)
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotColumnsAutoFit"
strErrorObject = "Pivot: " & pvt.Name & " Fields: " & CStr(strFieldNames)
''' standard procedure error handler end initialise '''
' Sets Column Widths to AutoFit
' accepts a comma-delimited list of Field Names
Const cStrDelim As String = ","
' e.g.
' PivotColumnsAutoFit pvt, "Phase,Class"
'
' If no names are specified then ALL columns will be autofitted
Excel.Application.ScreenUpdating = False
Dim bDoAllColumns As Boolean
bDoAllColumns = IsMissing(strFieldNames)
If Not bDoAllColumns Then
bDoAllColumns = strFieldNames = ""
End If
If bDoAllColumns Then
pvt.TableRange1.EntireColumn.AutoFit
Else
Dim fld As Excel.PivotField
Dim strDelimitedList, strNameWithDelims As String
' Make the delimited list easy to search by topping and tailing it
strDelimitedList = cStrDelim & strFieldNames & cStrDelim
For Each fld In pvt.PivotFields
' we autofit the column is EITHER no list was specified...
Dim bAutoFitThisColumn As Boolean
bAutoFitThisColumn = IsMissing(strFieldNames)
If Not bAutoFitThisColumn Then bAutoFitThisColumn = strFieldNames = ""
' OR if this field matches in the list
If Not bAutoFitThisColumn Then
strNameWithDelims = cStrDelim & fld.Name & cStrDelim
bAutoFitThisColumn = InStr(1, strNameWithDelims, strDelimitedList, vbTextCompare)
End If
If bAutoFitThisColumn Then
strErrorObject = fld.Name
'if fld.Orientation
fld.DataRange.EntireColumn.AutoFit
'If Not fld.DataRange.Columns.AutoFit = True Then
'fld.DataRange.Columns.AutoFit
'End If
End If
Next fld
End If
Excel.Application.ScreenUpdating = True
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
Function PivotTableFormat( _
pvt As Excel.PivotTable _
, Optional strTableStyle As String _
, Optional lThemeColor As Excel.XlThemeColor _
, Optional vTintAndShade As Variant _
)
''' standard procedure error handler begin initialise 130910.AMG '''
ErrorAlerts False
On Error GoTo ErrorHandler
Dim strErrorObject As String
Const cStrProcedureName As String = "PivotTableFormat"
strErrorObject = "Pivot: " & pvt.Name & " Style: " & strTableStyle
''' standard procedure error handler end initialise '''
Dim sht As Excel.Worksheet
Set sht = pvt.Parent
If Not IsMissing(strTableStyle) Then
pvt.TableStyle2 = strTableStyle
End If
If Not IsMissing(lThemeColor) Then
sht.Tab.ThemeColor = lThemeColor
End If
If Not IsMissing(vTintAndShade) Then
sht.Tab.TintAndShade = vTintAndShade
End If
' move the selection off the pivot to hide the wizard
' may need to calc number of page fields to choose correct row
sht.Cells(3, 1).Select
''' standard procedure error handler begin terminate 130813.AMG '''
Proc_Exit:
ErrorAlerts True
Exit Function
ErrorHandler:
ErrorAlerts True
HandleErrorWithMessage "Error trying to '" & cStrModuleName & "." & cStrProcedureName & "' (" & _
strErrorObject & ") " & vbCrLf & vbCrLf & _
"Error " & Err.Number & vbCrLf & """" & Err.Description & """"
Resume Proc_Exit
''' standard procedure error handler end terminate '''
End Function
Function PivotGrandTotals _
(pvt As Excel.PivotTable _
, bGrandTotalRow As Boolean _
)
pvt.RowGrand = bGrandTotalRow
End Function