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: Default Property/Methods for Objects in Visual Basic


View products that this article applies to.

This article was previously published under Q213652

↑ Back to the top


Summary

In Microsoft Visual Basic for Applications, if an object has a Value property, then this property is the default value for the object. If an object does not have the Value property, then that object does not have a default value.

↑ Back to the top


More information

The default value of an object is the value that is returned when you use the object in a procedure, without specifying a property or method for the object.

For example, if you use the Name object, without designating a specific property of Name, such as Count, the default value for Name is the Value property. The Value property of the Name object returns a string containing the formula that the name is defined to refer to.

In the following example, the Name object is used as an element of the Names collection, without a property.
   Sub Default_Name_Property()
       Dim n as Object
       For Each n In Names
           'Display default property of each Name
           '(Value property) in Names collection
           MsgBox n
       Next
   End Sub
				
When you run this macro, the formula that the name refers to is displayed in a dialog box for each name in the active workbook.

Collections

When you use a collection in a Visual Basic macro, you can use the Item method to return a part of the collection. The Item method is the default value for a collection. For example, the following code
ActiveWorkbook.Worksheets.Item(1)
				
is equivalent to:
 ActiveWorkbook.Worksheets(1)
				
The Item method is the default value for a collection in the same way that the Value property is the default value for those objects that have the Value property. Note that you can use the Item method with any collection.

↑ Back to the top


References

For more information about the Value property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Value Property (Excel) in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

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

↑ Back to the top


Keywords: KB213652, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 213652
Revision : 6
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 241