Updating PivotTable using command button on a locked sheet

kidwispa

Active Member
Joined
Mar 7, 2011
Messages
330
Hi all,

I currently have a command button within a protected sheet that when pressed runs a macro that refreshes the data in a pivot table and pivot chart. The problem is when I open the file it gives the error message "Cannot edit pivot table on protected sheet". When I unprotect the sheet, then protect it again ticking the "Use pivot table reports" option the macro works fine and I can go in and use the full functionality of the pivot chart as well. However, when I save the file it saves the fact that the sheet is password protected but not the 'use pivot table reports' bit, so when I reopen it the same error message appears.


My question is, can anyone help me write some code that, when the file is opened, ensures that the above error message doesn't happen?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Update - I've tried using the code below in the Workbook section of ThisWorkbook...

Code:
Private Sub Workbook_Open()
Worksheets("Results").Unprotect Password:="Password"
 
    Worksheets("Results").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowUsingPivotTables:=True
   Worksheets("Results").EnableSelection = xlUnlockedCells
 
Worksheets("Results").Protect Password:="Password"
 
End Sub

However the error message still comes up and the sheet gets protected but without the password assigned. Is it possible for this to work BEFORE the error message appears?
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,767
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top