XL: Can't Use Visual Basic Procedure to Reference Project

Last reviewed: March 27, 1997
Article ID: Q121269
5.00 5.00c 7.00 WINDOWS kbprg

The information in this article applies to:

  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, version 7.0

SYMPTOMS

In Microsoft Excel, you cannot use a Visual Basic procedure to establish a reference to a project or to an object library. For example, if you turn on the Macro Recorder, and you use the References dialog box in a Visual Basic module to establish a reference to a project or an object library, nothing is recorded.

NOTE: A project is any file that contains a Visual Basic for Applications module, such as an .XLS or .XLA file.

WORKAROUNDS

To establish a reference in a Visual Basic module to a project, when you will be copying the module to another computer, do either of the following:

  • In the module that you want to copy to a different computer, use the References dialog box (Tools menu) to reference the project before you copy the module to a different computer. Then copy the workbook that contains this module, and the referenced project to the same directory on the second computer. When you use this method, Microsoft Excel finds the referenced project and establishes the reference again when you run the procedure.

    You can also copy the referenced project to the Microsoft Excel directory, the Microsoft Windows directory, the Microsoft Windows SYSTEM subdirectory, or any directory that is in the MS-DOS path statement.

    -or-

  • You can call a Visual Basic procedure that is located in another project by first opening the project file, and then using the Run method of the Application object, and specifying the name of the referenced project and the name of the procedure as in the following example:

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.

   Workbooks.Open("BOOK1.XLS")
   Application.Run "BOOK1.XLS!Macro1"

MORE INFORMATION

For additional information, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q110755
   TITLE     : XL: Deleted Project or Library Listed Twice In References

When you open a Visual Basic module that references a project, Microsoft Excel searches for the referenced project file in the following directories:

   1. The directory that contained the project file when you first
      established the reference.

   2. The directory in which the file that contains the reference is
      located.

   3. The directory in which Microsoft Excel is installed.

   4. The directory in which Microsoft Windows is installed.

   5. The SYSTEM subdirectory of the Microsoft Windows directory.

   6. Any directory that is located in the path statement in the
      AUTOEXEC.BAT file.

REFERENCES

For more information about the References Command (Tools Menu), choose the Search button in Help and type:

   References command (Tools Menu)


KBCategory: kbprg
KBSubcategory:

Additional reference words: 7.00 1.00 5.00 5.00c
Keywords : kbprg
Version : 5.00 5.00c 7.00
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 27, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.