View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Martin Brown Martin Brown is offline
external usenet poster
 
Posts: 230
Default Chartobjects protected but it can still be deleted, edited andmoved by the user (yes, the sheet is protected)

On 19/12/2014 09:04, tskogstrom wrote:
... .Chart.ProtectFormatting = True
... .Chart.ProtectData = True
... .Chart.ProtectSelection = False

I use these protections in a protected worksheet for my chartobjects in my code in a excel 2010 xlsm
- It has worked fine for years in 2010.

Now, when I test it with Excel 2007 the code works fine too. No errors, and in the GUI the chartobject protection checkbox is locked. BUT:

In 2007 the chartobjects still are editable for the user and I can delete and move them however I like. The sheet is still protected.


I have a sneaky feeling allowing objects to be selected will be
responsible for the loophole. I haven't seen this fault myself.

For the sheet protection I use this code:

...
..
If cnReport.ProtectContents = False Then
cnReport.Protect Password:=shtPassX, DrawingObjects:=False, Contents:=True, Scenarios:=True
cnReport.EnableSelection = xlNoRestrictions
End If
..
...


I cannot understand it. Any bug known? Workarounds?

/Thanks and merry cristmas



##### Full code below for the interested ###

Sub ProtectCharts(sCrt As String)
'---------------------------------------------------------------------------' Procedure : ProtectCharts
' Purpose :
'---------------------------------------------------------------------------
Debug.Print " ### START ProtectCharts in ReportSpecificCode"
On Error GoTo ProtectCharts_Error
Application.EnableCancelKey = xlDisabled

cnReport.ChartObjects(sCrt).Chart.ProtectFormattin g = True
cnReport.ChartObjects(sCrt).Chart.ProtectData = True
cnReport.ChartObjects(sCrt).Chart.ProtectSelection = False

On Error GoTo 0

Exit Sub

ProtectCharts_Error:
Debug.Print " -ERROR- " & Err.Number & " (" & Err.Description & ") in procedure ProtectCharts of VBA Document cnReport"

End Sub

I'd be inclined to set protectselection = True as well in XL2007 to see
if that alters this behaviour.

I can't say I have noticed any protection issues with drawing objects
going from 2003 to 2007. Loads of bad race conditions and random
reassignment of the parameters of objects but nothing like this.

But I have never moved any code back from 2010 to 2007.

--
Regards,
Martin Brown