Incorrect Value Returned for Custom Property Linked To Content

ID: Q135101


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


SYMPTOMS

When you use the CustomDocumentProperties property to return the value of a linked custom property in your file, the incorrect value may be returned.

For example, if your custom property is linked to the Text type value "Test," the CustomDocumentProperties property may return an empty value for this property. If your custom property is linked to the Date type value "8/1/95," the CustomDocumentProperties property may return the value 1/1/80 instead of the correct value.


CAUSE

This behavior occurs if you use the CustomDocumentProperties property to set the value of a linked custom property and you have not displayed the Properties dialog box in this file.

When you add a linked custom property to a file using a Visual Basic macro, the application that has the file open, for example Microsoft Excel, cannot resolve the link to return the value. Because of this, the CustomDocumentProperties property returns a default value (see table below). When you display the Properties dialog box, (File menu) the application then loops through the linked properties and updates the values. Therefore, the linked values displayed on the Custom tab in the Properties dialog box are always correct.

The following table shows the default values that are displayed when you use the CustomDocumentProperties property to return the value for a linked customproperty that you created using a Visual Basic macro (assuming you have not displayed the Properties dialog box).


   Property Type    Default Value
   ------------------------------
   Text               Blank
   Date              01/01/80
   Number               0
   Yes or No          False 


WORKAROUNDS

To work around this behavior when you create a custom linked property using the CustomDocumentProperties property, use any of the following methods:

Method 1

(Microsoft Excel only) Programmatically display, then dismiss, the Properties dialog box in your Visual Basic procedure before you access the value of one of the custom linked properties in your file. For example, you can use a macro similar to the following to accomplish this.

Microsoft provides examples of Visual Basic 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. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line- continuation character. For more information about Visual Basic for Applications programming style, see the "Programming Style in This Manual" section in the "Document Conventions" section of the "Visual Basic User's Guide."

Note that you must create a reference in your module to the Microsoft Office 95 Object Library using the References dialog box before you run the following code.

   Sub Test()
      With ActiveWorkbook.CustomDocumentProperties
         ' Create custom property "LDate" linked to defined name "mydate"
         .Add Name:="LDate", linkToContent:=True, _
           Type:=offPropertyTypeDate, linkSource:="mydate"

         ' Create custom property "LResponse" linked to
         ' defined name "mydate"
         .Add Name:="LResponse", linkToContent:=True, _
           Type:=offPropertyTypeString, linkSource:="response"
      End With

      ' Display Properties dialog box to link custom values
      SendKeys "{ENTER}"
      Application.Dialogs(xlDialogProperties).Show

      ' Display value of property LDate
      MsgBox ActiveWorkbook.CustomDocumentProperties.Item("LDate")
      ' Display value of property LResponse
      MsgBox ActiveWorkbook.CustomDocumentProperties.Item("LResponse")

   End Sub 

Method 2

Display the Properties dialog box by clicking Properties on the File menu after creating the custom linked property and before accessing the value of the linked property in a Visual Basic macro.


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


MORE INFORMATION

You can use the Properties dialog box to create a custom property in your application. To link a custom property to specific content in a Microsoft Excel file, you must define a name in your workbook. The Link To Content check box is available only if you have a defined name in your workbook.


REFERENCES

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

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

Additional query words:

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


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