Home » excel » VBA Excel ActiveChart ProtectFormatting

VBA Excel ActiveChart ProtectFormatting

Posted by: admin May 14, 2020 Leave a comment

Questions:

I cant write a code that protects my chart from formatting. No error appears but after running the code I can still change formatting of the chart. Maybe you know how I can make it works.

 ActiveSheet.ChartObjects("Chart 2").Activate
 With ActiveChart
 Application.ActiveChart.ProtectFormatting = True
 End With
How to&Answers:

Except for the basics, your code looks fine to me. You can do this with one line however:

ActiveSheet.ChartObjects("Chart 2").Chart.ProtectFormatting = True

This works for me anyway. Obviously, this doesn’t stop the chart being changed through code.