XL: Default Property/Methods for Objects in Visual Basic

Last reviewed: February 3, 1998
Article ID: Q114857
The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel 97 for Windows
  • Microsoft Excel 98 Macintosh Edition

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.

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 displays 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.

REFERENCES

For more information on the Value and Item properties, follow the appropriate steps for your version of Microsoft Excel.

Microsoft Excel 97

  1. Click Contents and Index on the Help menu in Visual Basic Editor.

  2. Click the Index tab.

  3. For help with the Value Property, type "Value Property" and click Display.

    -or-

    For help with the Item Property, type "Item Property" and click Display.

Microsoft Excel 7.0

  1. On the Help menu, click Microsoft Excel Help Contents.

  2. Click the Contents tab.

  3. For help with the Value Property, click Visual Basic Reference, double-click Properties, and then select the Value property.

    -or-

    For help with the Item Property, click Visual Basic Reference, double-click Properties and then select the Item Property.

Microsoft Excel 5.0

  1. On the Help menu, click Contents.

  2. On the Help Contents screen, select Programming With Visual Basic.

  3. For help on the Value Property, in the Visual Basic Reference, click the Search button, and type:

          Value Property
    

    For help on the Item Property, in the Visual Basic Reference, click the Search button, and type:

          Item Property
    

  4. Click Show Topics, and then click the Go To button.


Additional query words: 5.00 5.00c 7.00 8.00 97 98 XL98 XL97 XL7 XL5
Keywords : kbprg xlvbainfo PgmCtrlsStd
Version : WINDOWS:5.0,5.0c,7.0,97; MACINTOSH:5.0,98
Platform : MACINTOSH 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: February 3, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.