PUB2002: Run-Time Error 9 When You Programmatically Change Color Schemes (289023)



The information in this article applies to:

  • Microsoft Publisher 2002

This article was previously published under Q289023

SYMPTOMS

in a Microsoft Publisher publication, when you run a Microsoft Visual Basic for Applications macro that changes the color scheme of the publication, the following (or similar) error message may appear:
Run-time error '9'

Subscript out of range
This error message appears when you attempt to use the following color schemes that are listed in the Publisher Color Schemes object model:
  • Celebration
  • Cherry
  • Ocean
  • Orange
  • Peach
  • Purple
NOTE: The color schemes on this list do not appear in the Apply a color scheme list in the Color Schemes pane.

The error message also appears when you attempt to use the Bluebird color scheme, which does appear in the Apply a color scheme list.

NOTE: There are four color schemes that appear in the Apply a color scheme list that are not listed in the Publisher Object Model:

Eggplant
Grove
Harbor
Tuscany

The error message does not appear if you use these color schemes in a macro.

CAUSE

This behavior occurs for the following reasons:
  • The Celebration, Cherry, Ocean, Orange, Peach, and Purple color schemes exist only in the Japanese version of Publisher. The Object Model libraries are not localized ,so that all of the color schemes that can be used in Publisher are listed in the Object Model, even when they are not provided for a specific locality.
  • The Bluebird color scheme is the default Publisher color scheme. This color scheme is not expected to be selected programmatically and is not included in the Object Model, and cannot be specifically called by Visual Basic for Applications.
  • The Eggplant, Grove, Harbor, and Tuscany color schemes were added to Publisher after the Object Model was created so they do not appear in the Object Model library; however, like custom color schemes that you create, these color schemes can be selected programmatically.

RESOLUTION

To resolve this behavior, programmatically select only the color schemes that appear in the Apply a color scheme list in the Color Schemes pane.

If you select a color scheme on the Apply a color scheme list other than Bluebird, and you want to change back to the Bluebird color scheme, click Bluebird on the Apply a color scheme list rather than attempting to change the color scheme programmatically.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

To select a color scheme using the Color Schemes pane, follow these steps:
  1. On the Format menu, click Color Schemes.
  2. In the Color Schemes pane, under Apply a color scheme, click the color scheme that you want.
To view the color schemes in the Object Model library, follow these steps:
  1. In Publisher, press ALT+F11 to start the Visual Basic editor.
  2. On the View menu, click Object Browser.
  3. Click the arrow in the Project/Library box (upper left box in the upper right pane), and then click Publisher.
  4. Under Classes, click PbColorScheme.
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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: To programmatically select a color scheme, use the steps in the following example:
  1. Start Publisher, and then open or create the publication that you want.
  2. Press ALT+F11 to start the Visual Basic editor.
  3. On the Insert menu, click Module.
  4. On the Module sheet, type the following code:
    'Names the macro
    Sub DifferentColor()
       'Adds an input box to allow you to enter the new color scheme
       Dim Newcolor As String
       Newcolor = InputBox("Change the Color Scheme to:", "Change Color Scheme")
       'applies the color scheme to the active document
       ActiveDocument.ColorScheme  = Application.ColorSchemes(Newcolor)
    End Sub
    						
  5. Press ALT+F11 to return to Publisher.
  6. On the Tools menu, point to Macro, and then click Macros.
  7. In the Macros dialog box, under Macro Name, click DifferentColor, and then click Run.

Modification Type:MajorLast Reviewed:11/5/2003
Keywords:kbbug kbpending KB289023