我试图防止图表在写入后被更改。我从网上收集了应该这样做的代码:
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
我在线上遇到错误MyChart.Protect
。我无法让它工作。