Microsoft Office Tutorials and References
In Depth Information
.HasTitle = True
.ChartTitle.Characters.Text = “Product Sales"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
The recorded macro will create the chart; however, you’ll see that there are additional and
redundant lines of code added to the macro. Be sure to remove unnecessary lines of code
within a recorded macro.
Defining the Chart Object Model
The Chart Object Model at times can be overwhelming due to the layering effect. However,
use the Object Browser in the Visual Basic Editor to help you get your bearings as you begin
the task of coding procedures involving charts.
The hierarchy of a chart is determined by its location. For example, when working with an
embedded chart, if you would like to modify the text contained within the ChartTitle you’ll
need to review the object levels. The top-level object is the Application . The Application object
contains the Wo rkbook object, and the Wo rkbook object contains a Wo rksheet object. The
Worksheet object contains a ChartObject object, which contains a Chart object. The Chart
object has a ChartTitle object, and the ChartTitle object contains a Characters object. The
Te xt property of the Characters object stores the text that is displayed as the chart’s title. To
summarize how each object is connected, refer to the following list:
However, when working with a chart that is located on its own sheet you’ll see that the hier
archy is simplified. A chart sheet is technically at the same level as the worksheet because it’s
simply a different type of sheet. Review the levels as indicated here, and notice that two levels
have been removed.
The Charts collection holds the collection of chart sheets in a workbook. The Wo rkbook
object is always the parent of the Charts collection. The Charts collection holds only the chart