Excel UserInterfaceonly=True

GRCArizona

Board Regular
Joined
Apr 24, 2010
Messages
95
Hi -

I'm trying to understand the 'UserInterface' feature in VBA. I have a file with several charts and macros. On one worksheet, if a macro is selected, it will add a Trendline on a chart. Since the worksheet is protected, the macro is erroring out at:

ActiveSheet.ChartObjects("Chart 1").Activate

Here is my code I'm using on the 'Worksheet_Open' event:

Dim wks As Worksheet
For Each wks In ThisWorkbook.Worksheets
wks.EnableOutlining = True
wks.Protect Password:="aaa", DrawingObjects:=False, Contents:=True, Scenarios:= _
False, UserInterfaceonly:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
Next wks

Is there anything else needed to allow for charts to be accessed?

thanks,
GRC
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Why not just unprotect the sheet while the macro runs?
 
Upvote 0
Why not just unprotect the sheet while the macro runs?

the macro is a 'Worksheet_Change' event. I've found that, even though my VBA Project is protected, all an end user needs to do is make a copy of the worksheet and the worksheet level code becomes visible in the newly created copy. So, if I use the 'unprotect' method, the end user could potentially see what password I'm using.
 
Upvote 0
But it would only be unprotected while the macro is running.
 
Upvote 0
But it would only be unprotected while the macro is running.


But, as I mentioned, if a user is savvy enough to copy my sheet, he will have access to the Worksheet Level code which would contain the password and can unprotect the original document.

The only way I can think of is to 'Call' a macro that would Unprotect the sheet and at the end of my Worksheet_Level code, call another macro to Protect it again. But I would have to put that on each worksheet.
 
Upvote 0
The only way I can think of is to 'Call' a macro that would Unprotect the sheet and at the end of my Worksheet_Level code, call another macro to Protect it again.
Exactly. Two lines of code.
 
Upvote 0

Forum statistics

Threads
1,211,803
Messages
6,104,073
Members
447,892
Latest member
madara uchiha

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