Microsoft KB Archive/211811

= XL2000: Run-Time Error Using Macro to Add Custom List =

Article ID: 211811

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q211811





SYMPTOMS
In Microsoft Excel 2000, if you run a Visual Basic for Applications macro that attempts to add a custom list to the application, you may receive the following error message:

Run-time error '1004': Method 'AddCustomList' of object '_Application' failed



CAUSE
This problem occurs if all of the following conditions are true:   The ListArray argument of the AddCustomList method directly refers to a range of cells in a worksheet, for example:       Application.AddCustomList ListArray:=Range("A1:A4") -and-

 The custom list that you want to add is identical to an existing custom list. For example, if the range of cells contains the words "Alpha," "Bravo," "Charlie," and "Delta," and a custom list containing these four words already exists, the problem occurs.



WORKAROUND
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:

https://partner.microsoft.com/global/30000104

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

To prevent this problem from occurring, do not refer directly to the range of cells in the ListArray argument. Instead, use a variable to temporarily hold the values from the cells, and then pass the values from the variable to the custom list.

The following example macro uses a variable to hold the values from the cells, and then passes the values from the variable to the custom list: Sub AddACustomList

' Dimension a variable to hold the values. Dim TempArray As Variant

' Populate the variable with the values from the range of cells. TempArray = Range("A1:A4")

' Create the custom list. Application.AddCustomList ListArray:=TempArray

End Sub Note that adding a custom list when an identical custom list already exists does not result in two identical custom lists. The result is only one custom list containing the items that you added.



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



MORE INFORMATION
In Microsoft Excel 2000, you can add custom lists to the application by doing either of the following:
 * On the Tools menu, click Options. Click the Custom Lists tab. Click Add or Import to add a new custom list to the application.

-or-
 * Add a custom list to the application by using the AddCustomList method in a Visual Basic macro.

The ListArray argument of the AddCustomList method can accept a reference to a range of cells, for example:   Application.AddCustomList ListArray:=Range("A1:A4") Or, the argument can accept an array of values, for example:   Application.AddCustomList ListArray:=Array("Alpha", "Bravo", "Charlie") If you use the first method, you receive an error message if the custom list you are creating is identical to an existing custom list. The second method always works correctly.

Additional query words: XL2000

Keywords: kbbug kberrmsg kbpending KB211811

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.