Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA adding chart title

Tags:

excel

vba

charts

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:

enter image description here

When I run my code, I get:

Object does not support this property or method
like image 987
user1681664 Avatar asked Apr 13 '15 23:04

user1681664


People also ask

How do you add a title to a chart?

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.

How do I automatically insert a chart title in Excel?

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.


1 Answers

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
like image 192
Dan Donoghue Avatar answered Oct 29 '22 09:10

Dan Donoghue