XL97: User-Defined Function with Application.Run Returns #VALUE!

Last reviewed: February 27, 1998
Article ID: Q170308
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SYMPTOMS

A user-defined Visual Basic for Applications function that carries out the Run method of the Application object (Application.Run) returns the #VALUE! error value.

CAUSE

Microsoft Excel enters recalculation mode when a user-defined function is called from a worksheet cell. While in recalculation mode, Application.Run is disabled.

RESOLUTION

To correct this problem, install Microsoft Excel 97 Service Release 1 (SR-1).

In Microsoft Excel 97, if you create a function that calls another user- defined function, call the function directly rather than using the Run method. (See the "More Information" section later in this article for sample code that demonstrates calling the function directly.)

There is no workaround if the user-defined function calls a function contained in a dynamic-link library (DLL or XLL). You must use Application.Run to call these functions.

STATUS

Microsoft has confirmed this to be a problem in Microsoft Excel 97 for Windows. This problem was corrected in Microsoft Excel 97 SR-1.

For additional information about SR-1, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q172475
   TITLE     : OFF97: How to Obtain and Install MS Office 97 SR-1

MORE INFORMATION

You can use the Run method of the Application object to run code written in the Visual Basic or Microsoft Excel 4.0 macro languages. You can also use the Run method to run functions contained in a DLL or XLL. With the exception of functions contained in a DLL or XLL, you can alternatively run functions by calling them directly from within another user-defined function as the following sample demonstrates.

Microsoft provides examples of Visual Basic for Applications 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

  1. Open a new workbook.

  2. Press ALT+F11 to start the Visual Basic Editor.

  3. On the Insert menu, click Module.

  4. Type the following functions in this new module:

          Function X()
    
              X = 15
          End Function
    
          Function Y()
              'Call the user-defined function X.
              Y = X()
          End Function
    
    

  5. Type the following in cell A1 in Sheet1 of this workbook:

          A1: =Y()
    

    The value returned to cell A1 is 15 instead of #VALUE!.

REFERENCES

For more information about user-defined functions, click the Office Assistant in the Visual Basic Editor, type "user-defined function", click Search, and then click to view "Function Statement".

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft 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


Additional query words: execute executes .xll .dll vba
Version : WINDOWS:97
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: February 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.