Excel UserInterfaceonly=True

GRCArizona

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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,833
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
93
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,833
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
93
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,833
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,968
Messages
5,856,579
Members
431,820
Latest member
martel_9

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