PRJ98: Run-time Error Using Project 95 Object Library

ID: Q173772

The information in this article applies to:

SYMPTOMS

If you run a Microsoft Visual Basic for Applications Sub procedure (or macro) that automates Microsoft Project 98 from a program that has a reference to the Microsoft Project for Windows 95, version 4.1 object library, you may receive the following error message:

   Run-time error '13':

   Type mismatch

CAUSE

Microsoft Project 98 is not backward compatible with the Microsoft Project 4.1 object library (Pj4en32.olb) and early binding.

WORKAROUND

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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/supportnet/refguide/ 

Use either of the following methods to work around the problem.

Method 1: Reference the Microsoft Project 8.0 Object Library

1. Open the module that contains the Automation code.

2. On the Tools menu, click References.

3. Click to clear the "Microsoft Project 4.1 Object Library" check box.

4. Click to select the "Microsoft Project 8.0 Object Library" check box.

5. Click OK.

Method 2: Use Late Binding

Declare your object variable as type Object, and then use the CreateObject Function or GetObject Function to set the value of the object variable. (Using this method, you will lose the advantages of early binding, including automatic type checking, faster code, and improved readability, so Method 1 is the preferred workaround.) The following two sample functions demonstrate the difference between early and late binding.

NOTE: Microsoft Project must be running for these examples to work properly.

   Sub EarlyBindingSample()
      Dim P as MSProject.Application
      Set P = CreateObject("MSProject.Application")
      P.SelectBeginning
      P.SetTaskField "Name", "test"
      MsgBox P.ActiveProject.Tasks(1).Name
   End Sub

   Sub LateBindingSample()
      Dim P as Object
      Set P = CreateObject("MSProject.Application")
      P.SelectBeginning
      P.SetTaskField "Name", "test"
      MsgBox P.ActiveProject.Tasks(1).Name
   End Sub

For more information about early and late binding, click the Office Assistant while in a module, type "CreateObject," click Search, and then click to view "CreateObject Function."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Visual Basic Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120802
   TITLE     : Office: How to Add/Remove a Single Office
               Program or Component

STATUS

Microsoft has confirmed this to be a problem in Microsoft Project 98. We are researching this problem and will post new information here as it becomes available.

REFERENCES

For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q163435
   TITLE     : VBA: Programming Resources for Visual Basic for
               Applications

Additional query words: vba
Keywords          :  
Version           : WINDOWS:98
Platform          : WINDOWS
Issue type        : kbbug
Solution Type     : kbpending

Last Reviewed: May 19, 1999