Changing Object Properties

After data is inserted into a worksheet, the data belongs to Microsoft Excel. You can then convert that data to a Microsoft Excel chart and customize the chart by changing its properties. The following code charts the data retrieved from Microsoft Project and customizes the chart by adding a legend and a blue title.


Dim newEmbeddedChart As ChartObject

Set newEmbeddedChart = Worksheets(1).ChartObjects.Add(50, 50, 250, 250)
With newEmbeddedChart.Chart
    .ChartWizard Source:=Worksheets(1).Range("A1:B4"), _
        Gallery:=xlPie, Format:=7, PlotBy:=xlColumns, _
        CategoryLabels:=1, SeriesLabels:=0, HasLegend:=2
    .HasTitle = True
    .ChartTitle.Text = "My Schedule"
    .ChartTitle.Font.Color = RGB(0, 0, 255)
    .HasLegend = True
End With