I simply want to add a chart title to my chart using vba. I actually want to do it recursively for every chart in every sheet, but I can't even get 1 chart to work. Here is the code I have:
Dim chnam
chnam = Left(ActiveSheet.Name, (Len(ActiveSheet.Name) - 9))
With ActiveWorkbook.ActiveSheet.ActiveChart
.HasTitle = True
.ChartTitle = chnam
End With
Here is my chart:
When I run my code, I get:
Object does not support this property or method
Add a chart titleClick the chart, and then click the Chart Layout tab. Under Labels, click Chart Title, and then click the one that you want. Select the text in the Chart Title box, and then type a chart title.
Click on the DESIGN tab. Open the drop-down menu named Add Chart Element in the Chart Layouts group. If you work in Excel 2010, go to the Labels group on the Layout tab. Choose 'Chart Title' and the position where you want your title to display.
Try this:
Dim chnam as string
chnam = Left(ActiveSheet.Name, (Len(ActiveSheet.Name) - 9))
With ActiveWorkbook.ActiveSheet.ActiveChart
.HasTitle = True
.ChartTitle.Select
.ChartTitle.Text = chnam
End With
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With