OFF: Run-Time Error Accessing BuiltinDocumentProperties (135099)



The information in this article applies to:

  • Microsoft Excel for Windows 95
  • Microsoft Excel 97 for Windows
  • Microsoft Project for Windows 95 4.1

This article was previously published under Q135099

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 sample 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 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: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

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.

Modification Type:MinorLast Reviewed:9/13/2006
Keywords:kberrmsg kbprb kbProgramming KB135099