Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: How to Use the ApplyCustomType Method to Format Charts


View products that this article applies to.

Summary

When you run a Microsoft Visual Basic for Applications macro in Microsoft Excel 2000, you can use the ApplyCustomType method to apply standard or custom chart types to a chart or a series in a chart.

This article explains how to use the ApplyCustomType method and its arguments.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Syntax

In Microsoft Excel 2000, the ApplyCustomType method uses the following syntax
Expression.ApplyCustomType(ChartType,TypeName)
where the arguments are as follows:
  • Expression is a Chart or Series object.
  • ChartType is a standard chart type, as listed in the Help topic for the ChartType property, or one of the following three constants:
    xlBuiltIn

    xlUserDefined

    xlAnyGallery
  • TypeName is the name of the custom chart type you want to apply to the chart. Use this argument only when ChartType is one of the three constants listed for ChartType, and when Expression refers to a Chart object (not a Series object).

The xlBuiltIn, xlUserDefined, and xlAnyGallery Constants

For ChartType, you can use the xlBuiltIn, xlUserDefined, and xlAnyGallery constants to determine the source of custom chart formats that the ApplyCustomType method will use. The sources that are used by each constant are listed in the following table.
   Constant        Source
   ---------------------------------------------------------------------
   xlBuiltIn       Uses custom chart formats in Xl8galry.xls. These
                   formats are included with Microsoft Excel 2000.

   xlUserDefined   Uses custom chart formats in Xlusrgal.xls. You create
                   these formats.

   xlAnyGallery    Uses custom chart formats in Xlusrgal.xls or
                   Xl8galry.xls.
				
To view the custom chart formats that are available in Xl8galry.xls and Xlusrgal.xls files, follow these steps:
  1. In Microsoft Excel, click a chart to select it.
  2. On the Chart menu, click Chart Type.
  3. On the Custom Types tab, under Select from, click the type of custom chart formats you want to view (User-defined or Built-in).
The names in the Chart type list are TypeName arguments for the ApplyCustomType method. For example, if you want to format the chart as a "Floating Bars" chart, use the following line of code:
   Charts(1).ApplyCustomType xlBuiltIn, "Floating Bars"
				
Because "Floating Bars" is a built-in custom chart format, use the xlBuiltIn constant. In most cases, you can also use the xlAnyGallery constant.

NOTE: If you specify an invalid TypeName argument, the following error message appears:
Run-time error '1004':
Application-defined or object-defined error
If you use the xlAnyGallery constant, Microsoft Excel first looks for the specified TypeName in Xlusrgal.xls. If the TypeName is not found, Microsoft Excel then looks in Xl8galry.xls. If the TypeName is still not found, you receive the error message.

Examples

Changing to a 3-D Line Chart Type

To change the active chart to a 3-D line chart, use the following line of code:
Sub test()
   ActiveChart.ApplyCustomType xl3DLine
End Sub
				
NOTE: In the following examples, the code does not work with embedded charts, only with charts created in a Chart Sheet. To apply the example to an embedded chart you must use the ChartObjects property, for example:
Sub test()
   ActiveSheet.ChartObjects(1).chart.applyCustomType xlbuiltin, "Floating Bars"
End Sub
				
Also, a user-defined chart must exist. The following examples use a fictitious user-defined chart named "Rainbow Columns."

Changing to a User-Defined Chart Type

To change the first chart in the workbook to a user-defined chart type called "Rainbow Columns" use either of the following lines of code:
Sub test()
   Charts(1).ApplyCustomType xlUserDefined, "Rainbow Columns"
End Sub
				
-or-
Sub test()
   Charts(1).ApplyCustomType xlAnyGallery, "Rainbow Columns"
End Sub
				

Changing to a Built-in Chart Type

To change the second chart in the workbook to a built-in chart type called "Outdoor Bars" use the following line of code:
Sub test()
   Charts(2).ApplyCustomType xlBuiltIn, "Outdoor Bars"
End Sub
				
Note that you can also use the following line of code:
Sub test()
   Charts(2).ApplyCustomType xlAnyGallery, "Outdoor Bars"
End Sub
				
However, this code does not achieve the same results if a user-defined chart type called "Outdoor Bars" also exists.

↑ Back to the top


References

For more information about creating charts, click Microsoft Excel Help on the Help menu, type Create a chart in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about using the ApplyCustomType method and the ChartType property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type ApplyCustomType Method in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB213521, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 213521
Revision : 8
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 311