Excel UserInterfaceonly=True

GRCArizona

Board Regular
Joined
Apr 24, 2010
Messages
92
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,784
Office Version
  1. 2010
Platform
  1. Windows
Why not just unprotect the sheet while the macro runs?
 

GRCArizona

Board Regular
Joined
Apr 24, 2010
Messages
92
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.
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,784
Office Version
  1. 2010
Platform
  1. Windows
But it would only be unprotected while the macro is running.
 

GRCArizona

Board Regular
Joined
Apr 24, 2010
Messages
92
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.
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,784
Office Version
  1. 2010
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,804
Messages
5,638,450
Members
417,025
Latest member
MusterDuster

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
Top