Visual Basic Add Method Fails If Object Already Exists (141766)
The information in this article applies to:
- Microsoft Excel 97 for Windows
- Microsoft Excel for Windows 95
- Microsoft Excel for Windows 5.0
- Microsoft Excel 98 Macintosh Edition
This article was previously published under Q141766 SYMPTOMS
In Microsoft Excel, when you create a Microsoft Visual Basic for
Applications macro and you attempt to add an object for the second time,
the Add method fails and you receive the following error message:
Run time error 1004: Add method of <collection> class failed
Where <collection> is the object collection used.
CAUSE
This error message occurs when the collection object of the same class and
name already exists, and you attempt to add it a second time with the same
name.
This behavior is by design of Microsoft Excel, because it eliminates the
possibility of having two objects of the same class with the same name.
REFERENCES
For more information about getting help with Visual Basic for Applications,
please see the following article in the Microsoft Knowledge Base:
163435
VBA: Programming Resources for Visual Basic for
Applications
Modification Type: | Minor | Last Reviewed: | 10/10/2006 |
---|
Keywords: | kbdtacode kberrmsg kbprb kbProgramming KB141766 |
---|
|