title: How do I protect chart code?
body: <p>I'm trying to keep a chart from being changed once it is written. I've gathered code from the web that should do this:</p>
  
  <pre><code>Sub test()
  Dim myChartObject As ChartObject
  Dim MyChart As Chart
  
  Set myChartObject = ActiveSheet.ChartObjects.Add(Left:=100, Top:=100, Width:=400, Height:=300)
  
  Set MyChart = myChartObject.Chart
  
  MyChart.PlotArea.Width = Application.InchesToPoints(2.583)
  MyChart.PlotArea.Height = Application.InchesToPoints(1.75)
  
  MyChart.ChartType = xlLine
  
  MyChart.SetSourceData Source:=ActiveWorkbook.ActiveSheet.Range("A5:D9")
  MyChart.Protect Password:="pass", DrawingObjects:=True, Contents:=True
  
  End Sub
  </code></pre>
  
  <p>I get an error on the <code>MyChart.Protect</code> line. I am not able to get it to work.</p>