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
 

shg

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

Forum statistics

Threads
1,085,060
Messages
5,381,488
Members
401,743
Latest member
andrezusp

Some videos you may like

This Week's Hot Topics

Top