Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Workbook protection and Pivot table on the fly

Background - I need to protect sheets in a workbook to prevent deletion of
the sheets. In the workbook, I currently have a pivot table. I would like
users to be able to drill-down.

Initial testing shows that drill-down requires an unprotected workbook. I
can deal with this - add code to the sheet to turn off protection when the
pivot sheet is activated, turn it on when deactivated. If done, how do I
stop the pvtSheet being zapped when protection is off? Alternatively, do I
write code to create a new pvtSheet and clean this up together with
drill-down sheets on exit?

The latter has the advantage of prevent users messing with the pivot layout
and saving saved file size. But, how do I deal with Excel's rejection of any
existing pivot table name?

Do I use a set pivot and deal with associated problems or build a fresh
pivot each time? I'm leaning towards the latter but, your comments would be
appreciated.

Steve


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Workbook protection and Pivot table on the fly

Hi Steve

If you mean drill down by double clicking on a value in the pivot table
you could get around this as follows. Start out with the Pivot Table
created and the workbook protected. Right click the pivot table sheet
and select view code. Add this before double click event:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target _
As Range, Cancel As Boolean)
ThisWorkbook.Unprotect password:="thepassword"
End Sub

This will unprotect the workbook and allow a new sheet to be created.

Then goto the ThisWorkbook Code module and add the following NewSheet event:

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Me.Protect password:="thepassword"
End Sub

This will protect the book again as soon as the newsheet is created.

Hope this helps
Rowan


Steve wrote:
Background - I need to protect sheets in a workbook to prevent deletion of
the sheets. In the workbook, I currently have a pivot table. I would like
users to be able to drill-down.

Initial testing shows that drill-down requires an unprotected workbook. I
can deal with this - add code to the sheet to turn off protection when the
pivot sheet is activated, turn it on when deactivated. If done, how do I
stop the pvtSheet being zapped when protection is off? Alternatively, do I
write code to create a new pvtSheet and clean this up together with
drill-down sheets on exit?

The latter has the advantage of prevent users messing with the pivot layout
and saving saved file size. But, how do I deal with Excel's rejection of any
existing pivot table name?

Do I use a set pivot and deal with associated problems or build a fresh
pivot each time? I'm leaning towards the latter but, your comments would be
appreciated.

Steve


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Workbook protection and Pivot table on the fly

And of course that will fail miserably as the workbook will be
unprotected if the user double clicks anywhere outside of the pivot table...

Change the double click event so that the target address (double clicked
cell) is within the pivot table data fields (C5:C11 in my example):

Private Sub Worksheet_BeforeDoubleClick(ByVal Target _
As Range, Cancel As Boolean)
If Not Intersect(Target, Range("C5:C11")) Is Nothing Then
ThisWorkbook.Unprotect
End If
End Sub

Regards
Rowan

Rowan Drummond wrote:
Hi Steve

If you mean drill down by double clicking on a value in the pivot table
you could get around this as follows. Start out with the Pivot Table
created and the workbook protected. Right click the pivot table sheet
and select view code. Add this before double click event:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target _
As Range, Cancel As Boolean)
ThisWorkbook.Unprotect password:="thepassword"
End Sub

This will unprotect the workbook and allow a new sheet to be created.

Then goto the ThisWorkbook Code module and add the following NewSheet
event:

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Me.Protect password:="thepassword"
End Sub

This will protect the book again as soon as the newsheet is created.

Hope this helps
Rowan


Steve wrote:

Background - I need to protect sheets in a workbook to prevent
deletion of the sheets. In the workbook, I currently have a pivot
table. I would like users to be able to drill-down.

Initial testing shows that drill-down requires an unprotected
workbook. I can deal with this - add code to the sheet to turn off
protection when the pivot sheet is activated, turn it on when
deactivated. If done, how do I stop the pvtSheet being zapped when
protection is off? Alternatively, do I write code to create a new
pvtSheet and clean this up together with drill-down sheets on exit?

The latter has the advantage of prevent users messing with the pivot
layout and saving saved file size. But, how do I deal with Excel's
rejection of any existing pivot table name?

Do I use a set pivot and deal with associated problems or build a
fresh pivot each time? I'm leaning towards the latter but, your
comments would be appreciated.

Steve

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Workbook protection and Pivot table on the fly

Rowan
That will do the trick. Thank you.

"Rowan Drummond" wrote in message
...
And of course that will fail miserably as the workbook will be unprotected
if the user double clicks anywhere outside of the pivot table...

Change the double click event so that the target address (double clicked
cell) is within the pivot table data fields (C5:C11 in my example):

Private Sub Worksheet_BeforeDoubleClick(ByVal Target _
As Range, Cancel As Boolean)
If Not Intersect(Target, Range("C5:C11")) Is Nothing Then
ThisWorkbook.Unprotect
End If
End Sub

Regards
Rowan

Rowan Drummond wrote:
Hi Steve

If you mean drill down by double clicking on a value in the pivot table
you could get around this as follows. Start out with the Pivot Table
created and the workbook protected. Right click the pivot table sheet and
select view code. Add this before double click event:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target _
As Range, Cancel As Boolean)
ThisWorkbook.Unprotect password:="thepassword"
End Sub

This will unprotect the workbook and allow a new sheet to be created.

Then goto the ThisWorkbook Code module and add the following NewSheet
event:

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Me.Protect password:="thepassword"
End Sub

This will protect the book again as soon as the newsheet is created.

Hope this helps
Rowan


Steve wrote:

Background - I need to protect sheets in a workbook to prevent deletion
of the sheets. In the workbook, I currently have a pivot table. I would
like users to be able to drill-down.

Initial testing shows that drill-down requires an unprotected workbook.
I can deal with this - add code to the sheet to turn off protection when
the pivot sheet is activated, turn it on when deactivated. If done, how
do I stop the pvtSheet being zapped when protection is off?
Alternatively, do I write code to create a new pvtSheet and clean this
up together with drill-down sheets on exit?

The latter has the advantage of prevent users messing with the pivot
layout and saving saved file size. But, how do I deal with Excel's
rejection of any existing pivot table name?

Do I use a set pivot and deal with associated problems or build a fresh
pivot each time? I'm leaning towards the latter but, your comments would
be appreciated.

Steve



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Workbook protection and Pivot table on the fly

You're welcome.

Steve wrote:
Rowan
That will do the trick. Thank you.



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
how can I auto refresh pivot table with sheet protection [email protected] Excel Discussion (Misc queries) 0 November 12th 08 10:34 PM
Sheet protection code conflicts with Pivot Table "auto refresh" KG Excel Discussion (Misc queries) 6 December 21st 05 11:16 PM
Excel 2002 Pivot Table Protection Kirk P. Excel Discussion (Misc queries) 1 February 23rd 05 10:08 PM
Pivot Table Protection mikeb Excel Discussion (Misc queries) 3 February 2nd 05 07:15 PM
Pivot table protection Joe[_35_] Excel Programming 0 October 18th 04 04:02 AM


All times are GMT +1. The time now is 09:30 AM.

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

About Us

"It's about Microsoft Excel"