XL97: How to Use the ApplyCustomType Method to Format Charts

Last reviewed: March 13, 1998
Article ID: Q167279
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SUMMARY

When you run a Visual Basic for Applications macro in Microsoft Excel 97, 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.

MORE INFORMATION

Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Syntax

In Microsoft Excel 97, 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

You can use the ChartType 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 97.

   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, do the following:

  1. In Microsoft Excel 97, click a chart to select it.

  2. On the Chart menu, click Chart Type. Then, click the Custom Types tab.

  3. 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, you receive the following error message:

   Run-time error '1004':
   Application-defined or object-defined error

If you use the xlAnyGallery constant, Microsoft Excel 97 first look for the specified TypeName in Xlusrgal.xls. If the TypeName is not found, Microsoft Excel 97 then looks in Xl8galry.xls. If the TypeName is not found, you receive the previous error message.

Examples

Changing to a 3-D Line Chart:

To change the active chart to a 3-D line chart, use the following line of code:

   ActiveChart.ApplyCustomType xl3DLine

Changing to a User-Defined Chart:

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:

   Charts(1).ApplyCustomType xlUserDefined, "Rainbow Columns"

-or-

   Charts(1).ApplyCustomType xlAnyGallery, "Rainbow Columns"

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:

   Charts(2).ApplyCustomType xlBuiltIn, "Outdoor Bars"

Note that you can also use the following line of code:

   Charts(2).ApplyCustomType xlAnyGallery, "Outdoor Bars"

However, this code does not achieve the same results if a user-defined chart type called "Outdoor Bars" also exists.

REFERENCES

For more information about using the ApplyCustomType method and the ChartType property, click the Office Assistant in the Visual Basic Editor, type "ApplyCustomType" or "ChartType"(without the quotation marks), click Search, and then click to view the topics.

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Excel Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120802
   TITLE     : Office: How to Add/Remove a Single Office
               Program or Component


Additional query words: XL97
Keywords : kbprg kbhowto
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.