Excel Books

Books that I own and use while developing in Excel

Excel User Conference

2008 US East Coast Excel User Conference
September 24-27, 2008
Atlantic City, NJ

 

Protecting a Chart Sheet

A chart sheet can be protected manually by selecting Protection from the Tools menu, then choosing Protect Sheet. Any combination of two options may be selected:

  • Protect Worksheet for Contents
    This option prevents changes to the chart's formats. Chart elements may be selected, but may not be changed. This option also prevents changes to a chart's data links, either through the series formula or through the Source Data dialog. If there are changes to worksheet data that the chart is linked to, the chart will update. Any objects (text boxes or shapes) on the chart are not protected.
     
  • Protect Worksheet for Objects
    This option prevents changes to any objects (text boxes or shapes) on the chart. If the text box is linked to a worksheet cell, and the contents of the cell change, the textbox will update. The formatting and source data of the chart may be changed.

The VBA equivalent of this manual sheet protection is:

ActiveChart.Protect Password:="drowssap", DrawingObjects:=True, Contents:=True

Note: despite being protected, the chart sheet may still be deleted.

Protecting a Chart Embedded in a Worksheet

An embedded chart can be protected manually by selecting Protection from the Tools menu, then choosing Protect Sheet. The Protect Worksheet for Objects option must be selected to protect the chart. This command prevents selection of the chart, and therefore it cannot be changed. If there are changes to worksheet data that the chart is linked to, the chart will update.

Protecting the sheet will only protect the chart if its parent chart object is locked (which is the default for an object). To change the Locked status of the chart, hold the Shift key while clicking on the chart to select the chart object. Selecting the chart object displays white handles (small resizing squares around the chart) rather than black handles. Select Object from the Format menu, click on the Protection tab, and check or uncheck the Locked checkbox.

The VBA equivalent of this manual sheet protection is:

ActiveSheet.Protect Password:="drowssap", DrawingObjects:=True

Selectively Protecting a Chart Using VBA

There are several protection-related properties of a chart which can be adjusted in VBA. These work the same way on chart sheets and on embedded charts.

  • ActiveChart.ProtectData = True
    This prevents changes to a chart's data links, either through the series formula or through the Source Data dialog. If there are changes to worksheet data that the chart is linked to, the chart will update. This has no effect on objects (text boxes and shapes) in the chart.
     
  • ActiveChart.ProtectFormatting = True
    This allows selection of individual chart elements, but prevents changes to the formatting of these elements, including the formatting of objects (text boxes and shapes) in the chart. Double-clicking is disabled, as are most right-click menu options. Changing the chart's data links is allowed.
     
  • ActiveChart.ProtectSelection = True
    This prevents selection of the chart or any of its elements. If an embedded chart is protected in this way, it cannot be selected (activated), so it must be referenced through its parent worksheet and chart object to unprotect:
    ActiveSheet.ChartObjects(1).Chart.ProtectSelection = False

  •