Len function returns incorrect values when you use it to calculate file properties in Microsoft Project (321665)



The information in this article applies to:

  • Microsoft Office Project Standard 2003
  • Microsoft Project Standard 2002

This article was previously published under Q321665

SYMPTOMS

In Microsoft Project, when you use the Len function to calculate the number of characters that are contained in the properties of a project file, an incorrect string value is returned.

For example, if the title of your project is defined as MyProject, and you use the Len function to return the string value of the title property, an incorrect value of 10 is returned, instead of the correct value of 9.

CAUSE

This behavior occurs if you use the Len function to return the number of characters contained in the file properties, including the following:

Title
Subject
Author
Manager
Company
Keywords
Comments

The Len function incorrectly returns the string value as length of the property + 1.

RESOLUTION

To work around this issue, use the Len function in a Visual Basic for Applications (VBA) macro. To do this, follow these steps:
  1. Create the macro:
    1. Start Microsoft Project, and then open your project file.
    2. Press ALT+F11 to start the Visual Basic Editor.
    3. On the Insert menu, click Module.
    4. In the Code window, type the following.

      NOTE: In this sample code, the macro returns the string value of the Title property of the file. To return the string value of a different file property, replace "Title" with the name of the property that you want.
      Sub ProjectTitle()
      
      res = Len(ActiveProject.Title)
      
      MsgBox res
      
      End Sub 
      						
    5. Press CTRL+S to save the file, and then click Close and Return to Microsoft Project on the File menu.
  2. Run the macro:
    1. Click Tools, point to Macro, and then click Macros.
    2. In the Macro name list, select the macro that you created in step 1, and then click Run.

      The string value of the file property is displayed.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Use the Len function in Visual Basic for Applications to calculate the number of characters of a text string that is contained in any object. For more information about the Len, function, type len in a Code window, and then press F1.

Modification Type:MinorLast Reviewed:1/7/2006
Keywords:kbProgramming kbprb kbnofix KB321665