Excel VBA Macro Show / Hide Chart Title

59 views Asked by At

Trying to hide Chart Title:

With objChart.Chart
        .ChartArea.AutoScaleFont = False '1
        .ChartType = xlColumnClustered '2
        .SetSourceData Source:=myDataRange '3
        .HasLegend = False '4
        .HasTitle = False '5
        '.SetElement (msoElementChartTitleNone) '6

Tried both (lines 5 and 6), neither work. Line 6 is from the recorded Macro. Any other way to do this? (.HasLegend works as expected)

1

There are 1 answers

0
Tim Williams On BEST ANSWER

This works fine for me:

Dim cht As Chart
Set cht = ActiveSheet.ChartObjects(1).Chart 'for example
    
'adds title
cht.HasTitle = True
cht.chartTitle.Text = "TitleHere"
    
'removes title
cht.HasTitle = False