VBA UserInterfaceOnly Refresh Pivot Table

ManUBlueJay

Active Member
Joined
Aug 30, 2012
Messages
326
Office Version
  1. 365
Platform
  1. Windows
THere have been several discussions on this but I cannot find a solution.

I used the following code on workbook_open
Worksheets("Inventory").Protect UserInterfaceOnly:=True, AllowUsingPivotTables:=True

I would expect it to allow code to run on that sheet including refreshing Pivot tables, but it fails with the message"RunTime Error 1004. That another sheet is protected using the same data"

Can anyone help
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
The way I read it is that you have some sheets somewhere that is protected (not userinterface only) and linked to the pivot table (like a graph for example) or other pivot tables if you refresh tham all. Or maybe the sheet where the data is (but that should not be an issue).

If you unprotect all other sheets do you have the problem? If not, protect them one by one to identify the error.

Note: to avoid this issue, Igenerally run a macro protecting all my sheets with Userinterfaceonly on open workbook event.
 
Upvote 0
I Did as you noted "run a macro protecting all my sheets with Userinterfaceonly on open workbook event"
I would expect that all my macros should now run irregadless of protection, but that does not seem to be the case
 
Upvote 0
All Sheets are unprotected. Only the active sheet is protected with allowing pivot turned turned on. It allows you to change the pivot but not refresh. It only allows refresh when I unprotect the sheet
 
Upvote 0
Strange and frustrating. I usually refresh my pivot tables automatically when coming on their sheet, so user who barely know anything in Excel have no issue and I work with updated data all the time (in addition it saves time). In your case, you could unprotect the sheet, refresh the pivot and protect it again using your code. To have a macro that run when coming on the sheet, right click the sheet, click "view code" and paste this
Code:
Private Sub Worksheet_Activate()
ActiveSheet.Unprotect
ActiveWorkbook.RefreshAll
ActiveSheet.Protect
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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