Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
lee lee is offline
external usenet poster
 
Posts: 184
Default Restrict Pivot Tables

Below is a sample of a pivot table that I'm trying to restrict. Found code
on the web that allows me to do it but I'm having a problem

Sub h_PT_Restrict_PivotTable()
'Restrict pivot table functionality
Dim pf As PivotField
With ActiveSheet.PivotTables(1)
.EnableWizard = False
.EnableDrilldown = False
.EnableFieldList = False 'Excel 2002+
.EnableFieldDialog = False
.PivotCache.EnableRefresh = False
For Each pf In .PivotFields
'If pf.Value = "Data" Then End
With pf
.DragToPage = False
.DragToRow = False
.DragToColumn = False
.DragToData = False
.DragToHide = False
End With
Next pf
End With
End Sub

This works fine until it hits "Data". I can put a watch on it and see it
run through all of the pivot fields. It will run through each field coming
to "Data" last. When the pf value becomes "Data" the macro stops on
..DragToPage = False with an application defined or object defined error.

Any ideas ? I put an If statement (commented out above) that when the pf
value = "Data" then end. This works fine as long as the user doesn't change
"Data" to anything else, if they do then it's back to the same problem.
Should it read "Data" as a pivot field?

Data
TASK ID DESCRIPTION Labor Cost Other Cost
1.1 Base Year Labor $ 131,596 $ 9,527
2.1 Option Period 1 Labor $ 542,806 $ 39,296
3.1 Option Period 2 Labor $ 575,364 $ 41,653
4.1 Option Period 3 Labor $ 610,398 $ 44,189
5.1 Option Period 4 Lalbor $ 647,571 $ 46,880
Grand Total $2,507,735 $ 181,545

--
Lee
  #2   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default Restrict Pivot Tables

If I understand your situation correctly, the error occurs when you try to
modify the .DragToPage "property" of the pivotfield that is in essence
contains your data. I did a quick review of the pivotfields and pivotfield
collection object, and it looks like you could instead of going through each
pivotfield as an entire collection, you could go through each type of
pivotfield that is in the pivot table. This would allow you to omit
performing the text comparison of pf.value = "Data" and coming across the
error that is stopping your code.

An alternate method, though I didn't see exactly how to accomplish it is to
check for the type of the pivotfield that is being evaluated. It would
appear that to do this you would have to use the same fields that would be
used above, so might as well do that from the start. :)

So you could loop through each columnfield, datafield, hiddenfield,
pagefield, rowfield, and/or visiblefield as necessary instead of just
Pivotfields. That way if the attribute "Data" is a member of the datafields
then it would be omitted by going through all of the other field types.

It would be the same setup as you have for the most part, but instead of for
each pf in .pivotfields it would be the respective .datafields,
..columnfields, .hiddenfields, etc.. then the next "group", then the next
"group" until you are done.

This way it would not matter whether the user changes the name "Data" or
not, but would limit based on the type of information being addressed.

"Lee" wrote:

Below is a sample of a pivot table that I'm trying to restrict. Found code
on the web that allows me to do it but I'm having a problem

Sub h_PT_Restrict_PivotTable()
'Restrict pivot table functionality
Dim pf As PivotField
With ActiveSheet.PivotTables(1)
.EnableWizard = False
.EnableDrilldown = False
.EnableFieldList = False 'Excel 2002+
.EnableFieldDialog = False
.PivotCache.EnableRefresh = False
For Each pf In .PivotFields
'If pf.Value = "Data" Then End
With pf
.DragToPage = False
.DragToRow = False
.DragToColumn = False
.DragToData = False
.DragToHide = False
End With
Next pf
End With
End Sub

This works fine until it hits "Data". I can put a watch on it and see it
run through all of the pivot fields. It will run through each field coming
to "Data" last. When the pf value becomes "Data" the macro stops on
.DragToPage = False with an application defined or object defined error.

Any ideas ? I put an If statement (commented out above) that when the pf
value = "Data" then end. This works fine as long as the user doesn't change
"Data" to anything else, if they do then it's back to the same problem.
Should it read "Data" as a pivot field?

Data
TASK ID DESCRIPTION Labor Cost Other Cost
1.1 Base Year Labor $ 131,596 $ 9,527
2.1 Option Period 1 Labor $ 542,806 $ 39,296
3.1 Option Period 2 Labor $ 575,364 $ 41,653
4.1 Option Period 3 Labor $ 610,398 $ 44,189
5.1 Option Period 4 Lalbor $ 647,571 $ 46,880
Grand Total $2,507,735 $ 181,545

--
Lee

  #3   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default Restrict Pivot Tables

I thought I had responded to this earlier, but didn't see that my response
made it to the site. :\

Instead of going through every pivot field, I would recommend looking up the
help info on the pivotfields object while in VBA. You should note that there
is a datafields group (or similar). If in fact you are trying to address
each type of field and restrict certain actions, then you could go through
each type of field and apply only the actions applicable to that field type.
It would seem that the word "data" applies to your datafield, and therefore
because there is no .dragtopage for the datafield, you are experiencing the
problem that you are and in the hard place that you have found yourself. :)

This way you can go through each type of field one after another and lock
down what you are wanting, assuming that the user isn't able to modify or
stop the code and be mischevious. :}

"Lee" wrote:

Below is a sample of a pivot table that I'm trying to restrict. Found code
on the web that allows me to do it but I'm having a problem

Sub h_PT_Restrict_PivotTable()
'Restrict pivot table functionality
Dim pf As PivotField
With ActiveSheet.PivotTables(1)
.EnableWizard = False
.EnableDrilldown = False
.EnableFieldList = False 'Excel 2002+
.EnableFieldDialog = False
.PivotCache.EnableRefresh = False
For Each pf In .PivotFields
'If pf.Value = "Data" Then End
With pf
.DragToPage = False
.DragToRow = False
.DragToColumn = False
.DragToData = False
.DragToHide = False
End With
Next pf
End With
End Sub

This works fine until it hits "Data". I can put a watch on it and see it
run through all of the pivot fields. It will run through each field coming
to "Data" last. When the pf value becomes "Data" the macro stops on
.DragToPage = False with an application defined or object defined error.

Any ideas ? I put an If statement (commented out above) that when the pf
value = "Data" then end. This works fine as long as the user doesn't change
"Data" to anything else, if they do then it's back to the same problem.
Should it read "Data" as a pivot field?

Data
TASK ID DESCRIPTION Labor Cost Other Cost
1.1 Base Year Labor $ 131,596 $ 9,527
2.1 Option Period 1 Labor $ 542,806 $ 39,296
3.1 Option Period 2 Labor $ 575,364 $ 41,653
4.1 Option Period 3 Labor $ 610,398 $ 44,189
5.1 Option Period 4 Lalbor $ 647,571 $ 46,880
Grand Total $2,507,735 $ 181,545

--
Lee

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
Building pivot tables in Excel 2007 based on existing pivot tables? [email protected] Excel Discussion (Misc queries) 4 December 26th 07 08:05 PM
(Tom?) Pivot tables, code to refer to all pivot tables on template klysell Excel Programming 0 July 20th 07 09:32 PM
How to restrict printing to only completed tables in spreadsheet?. Karen@NS Excel Discussion (Misc queries) 0 June 21st 06 07:49 PM
Restrict pivot table PK Excel Worksheet Functions 1 January 23rd 06 10:09 PM
Pivot tables-controlling user interaction with pivot tables Sindhura Excel Programming 0 August 27th 03 02:10 PM


All times are GMT +1. The time now is 06:17 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"