View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Hans Hans is offline
external usenet poster
 
Posts: 25
Default Change PivotField Item with macro

William

I finally found out why it doesnt run on some
pivottables...the autosort option of the field 'period'
should be on manual and not 'ascending' or 'descending'.
It works fine now.

Hans
-----Original Message-----
Hans

Untested, but try refreshing all pivot tables at the

start of your macro.
--
XL2002
Regards

William



"Hans" wrote in

message
...
| Hi All
|
| I have written a simple macro for a workbook that

contains
| a great number of Pivot Tables (all linked to external
| databases or other pivottables). It adds a new item
| (number 2) to the field period; See PivotChangePeriod.
|
| Unfortunately, it does not work on all Pivot Tables and
| then gives the error message "Unable to set the visible
| property of the PivotItem class". I have no idea why it
| does this. All Pivot Tables that are covered by the

macro
| contain field period with item 2 and I can manually add

it
| without any problem (when added, it does not overwrite
| other pivot tables or something like that). Also, when I
| record this with the macro recorder, it gives the same
| codes as in the macro.
|
| Any idea what I might be doing wrong?
|
| regards,
| Hans
|
| Sub PivotChangePeriod()
|
| Dim PT As PivotTable
| Dim Sh1 As Sheets
| Dim wk As Worksheet
|
| Set Sh1 = Worksheets(Array('10sheets')
|
| For Each wk In Sh1
| For Each PT In wk.PivotTables
| PT.PivotFields("period").PivotItems("2").Visible
| = True
| Next PT
| Next wk
|
| End Sub
|
|



.