Run-Time Error Accessing BuiltinDocumentProperties

ID: Q135099


The information in this article applies to:
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel 97 for Windows
  • Microsoft Project for Windows 95, version 4.1


SYMPTOMS

When you run a Visual Basic macro that uses the Value property to return the value of a built-in document property, you may receive an error message.

With Microsoft Excel version 7.0 or Microsoft Project version 4.1, you may receive the following error message.

Run-time error '440':
OLE Automation error
With Microsoft Excel 97, you may receive the following error message.
Run-time error '-2147467259 (80004005)':
Method 'Value' of object 'DocumentProperty' failed


CAUSE

This problem may occur when you use the BuiltinDocumentProperties property to return the value of a property if the property does not contain a value.

If a document property has not been set (does not contain a value), you may receive a run-time error when you use the Value property in a Visual Basic macro to return the value of the property. For example, you receive a run-time error when you run either of the following commands in a Microsoft Excel workbook if the workbook has not been printed:


   MsgBox ActiveWorkbook.BuiltinDocumentProperties.Item(10).Value 

   MsgBox _
   ActiveWorkbook.BuiltinDocumentProperties.Item("Last Print Date").Value 
Microsoft Office Visual Basic Help states that if the application doesn't define a value for one of the built-in document properties, reading the Value property for that document property causes an error.

The following is the list of built-in properties accessible through the BuiltinDocumentProperties property:
Title
Subject
Author
Keywords
Comments
Template
Last Author
Revision Number
Application Name
Last Print Date
Creation Date
Last Save Time
Total Editing Time
Number of Pages
Number of Words
Number of Characters
Security
Category
Format
Manager
Company
Number of Bytes
Number of Lines
Number of Paragraphs
Number of Slides
Number of Notes
Number of Hidden Slides
Number of Multimedia Clips
Hyperlink Base ** Microsoft Office 97 only
Number of characters (with spaces) ** Microsoft Office 97 only


WORKAROUND

To work around this problem, use the following example macro in Microsoft Excel to detect if the value for a built-in document property has been set and trap the run-time error. This macro loops through every built-in property and displays a dialog box with the name of the property on the first line, and the value of the property on the second line. If the property has not been set, the message "Not Set" is displayed instead of the value for that property. Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft Support professionals can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

NOTE: Before you run this macro, you must establish a reference in your module to the Microsoft Office 95 Object Library or the Microsoft Office 8.0 Object Library using the References dialog box. The Microsoft Office 95 Object Library file (MSO5ENU.DLL) is located in the Windows\System folder. The Microsoft Office 8.0 Object Library file (MSO97.DLL) is located in the folder \Program Files\Microsoft Office\Office.


   Sub DisplayProperties()

      Dim v as String

      ' Initiate error handler
      On Error Resume Next

      ' iterate through each built-in property
      For Each x In ActiveWorkbook.BuiltinDocumentProperties
         ' attempt to return value of property
         v = x.Value
         ' if property not set, error 440 will occur
         If Err = 440 Then
            ' reset error handler
            Err = 0
            ' prepare "Not Set" message
            v = "Not Set"
         End If

         ' display property name, and value or "Not Set" if applicable
         MsgBox x.Name & Chr(10) & v
      Next x

End Sub 
Note that to use this example macro in Microsoft Project, change the following statement in the macro:

   For Each x In ActiveWorkbook.BuiltinDocumentProperties 
to the following:

   For Each x In ActiveProject.BuiltinDocumentProperties 


REFERENCES

For more information about using the BuiltinDocumentProperties property in Microsoft Excel, click the Index tab in Microsoft Excel Help, type the following text

BuiltinDocumentProperties
double-click the selected text and then double-click "BuiltinDocumentProperties Property" to go to the "BuiltinDocumentProperties Property" topic.

Additional query words: 7.0a xl97 built-in document properties

Keywords :
Version : WINDOWS:4.1,7.0,97
Platform : WINDOWS
Issue type :


Last Reviewed: October 20, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.