How to Run VB for Apps Code from an MS Excel 4.0 Macro Sheet

Last reviewed: September 2, 1997
Article ID: Q149998

The information in this article applies to:
  • Microsoft Excel for Windows, version 5.x
  • Microsoft Excel for Windows 95, version 7.0

SUMMARY

In Microsoft Excel versions 5.0 and 7.0, you are able to call a Microsoft Excel version 5.0 or 7.0 Visual Basic for Applications procedure from a Microsoft Excel version 4.0 macro.

MORE INFORMATION

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.

To call a Visual Basic for Applications macro from a Microsoft Excel version 4.0 macro, do the following:

  1. Insert both a Module and a 4.0 Macro sheet in a Microsoft Excel version 5.0 or 7.0 workbook.

  2. Place the following code on the Module sheet:

          Sub Test()
             Msgbox "This is a test"
          End Sub
    
    

  3. Save the workbook as VBA_XLM.xls.

  4. On the 4.0 Macro sheet, place the following code:

          A1: Test1
          A2: =RUN(VBA_XLM.xls!test())
          A3: =RETURN()
    

  5. On the 4.0 Macro sheet, place your cursor in cell A1, and do the following:

    a. On the Insert menu, point to Name, and then click Define.

    b. In the Define Name dialog box, click Test1 in the Names In Workbook

          list.
    

    c. Under Macro, click Command.

          The Category list defaults to User Defined.
    

    d. Click Add, and then click OK.

  6. Save the workbook.

  7. On the Tools menu, click Macro.

  8. In the Macro dialog box, click Test1, and then click Run.

    You should receive a dialog box with the message "This is a test."

REFERENCES

"Microsoft Excel Function Reference," version 4.0, pages 367-368 "Microsoft Excel User's Guide 2," version 4.0, pages 231-255 "Microsoft Excel Visual Basic User's Guide," version 5.0, chapters 1-4


Additional query words: 4.00 5.00 5.0 5.0c 5.00c 7.00
Keywords : PgmHowTo kbcode kbhowto kbprg
Version : 5.x 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: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.