Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Working with Pivot Tables in VBA

Hi,

I'm just looking at pivot table stuff via VBA for the
first time and am having some hassles:

..PivotItems(x).Visible = True

is returning a 'run time error 1004 app/object defined
error' for PivotItems in a given collection (when the
property is initially manually set to False prior to
running), whereas the same property set to false via
script, on the same item (after manually setting to True)
works fine. I can't work out what is going wrong... I'm
using XL2000. Any ideas??




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Working with Pivot Tables in VBA

Debrah Dalgleish had written about this:

http://groups.google.com/groups?thre...ontextures.com
To prevent the error, set the Sort for the field to Manual. You can do
this in the code, for example:

Sub PivotShowItemAllField()
'For version 2000 -- show all items in specific field
'sort is set to Manual to prevent errors, e.g.
'unable to set Visible Property of PivotItem class
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveSheet.PivotTables(1)
Set pf = pt.PivotFields("Salesman")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
With pt.PivotFields("Salesman")
pf.AutoSort xlManual, pf.SourceName
For Each pi In pf.PivotItems
If pi.Visible < True Then
pi.Visible = True
End If
Next pi
pf.AutoSort xlAscending, pf.SourceName
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub



--
Regards,
Tom Ogilvy

"Marshall" wrote in message
...
Hi,

I'm just looking at pivot table stuff via VBA for the
first time and am having some hassles:

.PivotItems(x).Visible = True

is returning a 'run time error 1004 app/object defined
error' for PivotItems in a given collection (when the
property is initially manually set to False prior to
running), whereas the same property set to false via
script, on the same item (after manually setting to True)
works fine. I can't work out what is going wrong... I'm
using XL2000. Any ideas??






  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Working with Pivot Tables in VBA

Thanks Tom, much appreciated. Will check this out.

-----Original Message-----
Debrah Dalgleish had written about this:

http://groups.google.com/groups?threadm=3EFB17B7.90707%

40contextures.com
To prevent the error, set the Sort for the field to

Manual. You can do
this in the code, for example:

Sub PivotShowItemAllField()
'For version 2000 -- show all items in specific field
'sort is set to Manual to prevent errors, e.g.
'unable to set Visible Property of PivotItem class
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveSheet.PivotTables(1)
Set pf = pt.PivotFields("Salesman")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
With pt.PivotFields("Salesman")
pf.AutoSort xlManual, pf.SourceName
For Each pi In pf.PivotItems
If pi.Visible < True Then
pi.Visible = True
End If
Next pi
pf.AutoSort xlAscending, pf.SourceName
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub



--
Regards,
Tom Ogilvy

"Marshall" wrote

in message
...
Hi,

I'm just looking at pivot table stuff via VBA for the
first time and am having some hassles:

.PivotItems(x).Visible = True

is returning a 'run time error 1004 app/object defined
error' for PivotItems in a given collection (when the
property is initially manually set to False prior to
running), whereas the same property set to false via
script, on the same item (after manually setting to

True)
works fine. I can't work out what is going wrong...

I'm
using XL2000. Any ideas??






.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Icon - Working with Pivot tables HW Excel Discussion (Misc queries) 1 December 23rd 09 07:10 PM
Auto Refresh of Pivot Tables not working meo Excel Worksheet Functions 0 March 13th 08 05:31 PM
Working with Pivot tables with % change Charlie Excel Worksheet Functions 0 July 28th 06 04:20 PM
How do I disable "Get Pivot Data" when working from pivot tables? Frustrated excel 2003 user Excel Worksheet Functions 2 November 29th 05 12:00 AM
Working with Pivot Tables M.Siler Excel Discussion (Misc queries) 2 June 27th 05 02:17 PM


All times are GMT +1. The time now is 09:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"