View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
tskogstrom[_2_] tskogstrom[_2_] is offline
external usenet poster
 
Posts: 13
Default Chartobjects protected but it can still be deleted, edited and movedby the user (yes, the sheet is protected)

.... .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.

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



Sub CallProtectCharts()
'---------------------------------------------------------------------------
' Procedure : CallProtectCharts
' Purpose -
'---------------------------------------------------------------------------
Debug.Print " ### START CallProtectCharts in ReportSpecificCode"
On Error GoTo CallProtectCharts_Error
Application.EnableCancelKey = xlDisabled

If ReportUpdate = True Then
UppdateSplashReport ("Protect Report Charts")
Application.EnableCancelKey = xlDisabled
End If
Debug.Print " START- CallProtectCharts in cnReport"

ProtectCharts ("CRT_Pie_Expandables_RVA")
ProtectCharts ("CRT_Pie_Ben_RVA")
ProtectCharts ("Chr_Bubb_Ben_RVA")
ProtectCharts ("Chr_Bubb_Exp_RVA")
ProtectCharts ("REP_Cashflow_RVA")
ProtectCharts ("RepChrt_BCARelRVA")
ProtectCharts ("RepCashFlowAlts")


On Error GoTo 0
Debug.Print " ooo EXIT CallProtectCharts in ReportSpecificCode"
Exit Sub

CallProtectCharts_Error:
Debug.Print "Error " & Err.Number & " (" & Err.Description & ") in procedure CallProtectCharts of Module ReportSpecificCode"

End Sub