XL: How to Avoid the Error "Can't Find Project or Library"

ID: Q131298

The information in this article applies to:

SYMPTOMS

In Microsoft Excel, when you open a workbook that contains a reference to another workbook or add-in, you may receive the following error message:

   Can't find project or library

CAUSE

You can access functions and macros in another workbook by establishing a reference to that workbook. This reference is established by choosing the References command from the Tools menu and then selecting the workbook containing the functions and/or macros.

When you establish a reference to another workbook in this manner, Microsoft Excel hard-codes the path of the file when the reference is established. When you open a Microsoft Excel file that has a saved reference, Microsoft Excel searches for the file in the following places:

This can present problems when workbooks are moved to different computers.

If Microsoft Excel can find the file in any of these locations, the reference will be successfully established. If the file cannot be found, you may receive the error message "Can't find project or library."

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/support/supportnet/refguide/

To avoid this error message, use either of the following methods.

Method 1

Move the workbook that is referenced to any of the locations specified above.

Method 2

Use the Run method of the Application instead of using the References command on the Tools menu.

For example, if you have the following macro in a workbook that has a reference established to the add-in XLODBC.XLA:

   Sub GetData()

      Dim r As Integer
      Dim c As Integer
      Dim chan As Variant

      ' Establish a channel to the data source Nwind.
      chan = Sqlopen("DSN=NWIND")

      ' Execute a query on the channel to return all the records from
      ' the EMPLOYEE table.
      c = Sqlexecquery(chan, "SELECT * FROM EMPLOYEE")

      ' Return the data from the query to A1 on the active sheet.
      r = Sqlretrieve(chan, ActiveSheet.Cells(1))

      ' Close the channel.
      Sqlclose chan

   End Sub

You could replace this macro with the macro below. You do not need to establish a reference to XLODBC.XLA to run this macro:

   Sub GetData()

      Dim r as Variant
      Dim c as Variant
      Dim chan as Variant

      ' Open the add-in XLODBC.XLA which is located in the \MSQUERY
      ' subdirectory of the Microsoft Excel Library directory.
      Workbooks.Open (Application.LibraryPath _
         & "\MSQUERY\XLODBC.XLA")

      ' Depending on the add-in, you may need to use the
      ' RunAutoMacros method to run the add-ins auto-open procedures.
      ' For example, the Analysis ToolPak - VBA add-in (ATPVBAEN.XLA)
      ' needs to run its auto-open procedure before you can use the
      ' NETWORKDAYS() function. The line would read as follows:
      '
      '    Workbooks("ATPVBAEN.XLA").RunAutoMacros (xlAutoOpen)

      ' Establish a channel to the data source Nwind.
      chan = Run("XLODBC.XLA!Sqlopen", "DSN=NWIND")

      ' Execute a query on the channel to return all the records from
      ' the EMPLOYEE table.
      c = Run("XLODBC.XLA!Sqlexecquery", chan, _
         "SELECT * FROM EMPLOYEE")

      ' Return the data from the query to A1 on the active sheet.
      r = Run("XLODBC.XLA!Sqlretrieve", chan, ActiveSheet.Cells(1))

      ' Close the channel.
      Run "XLODBC.XLA!Sqlclose", chan

   End Sub

MORE INFORMATION

For additional information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q124277
   TITLE     : XL5 Err Msg: "Can't Find Project or Library" Running Macro

REFERENCES

"Developing Microsoft Excel 5 Solutions," Eric Wells, Microsoft Press, pages 576-577.

Additional query words: addin locate

Keywords          : kbcode kbprg PgmHowto 
Version           : WINDOWS: 5.0, 5.0c, 7.0; MACINTOSH: 5.0, 5.0a
Platform          : MACINTOSH WINDOWS
Issue type        : kbprb

Last Reviewed: May 18, 1999