Search code examples
excelvbachartstitle

Excel VBA Macro Show / Hide Chart Title


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)


Solution

  • 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