Chart Title Legend and Data TableVBA Name Chart Title Has Legend and Has DataTable

You can specify the location, text, and text format of the chart title and legend with VBA. You can also specify whether the chart has a data table containing the source data. The following code adds a chart title to the chart, sets the font size to 16, and places the title at the top-left corner of the chart. The legend is moved to the bottom. It also adds the data table to the chart.

Notice that it is necessary to set the HasProperty value to True before working with any of these elements:

Sub DemoMisc()

With Charts("Chart1") .HasTitle = True With .ChartTitle

.Text = "Company Performance" .Font.Size = 16 .Top = 0 .Left = 0 End With

.HasLegend = True .Legend.Position = xlBottom .HasDataTable = True End With End Sub

0 0

Post a comment