Microsoft KB Archive/149998

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

Article ID: 149998

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 5.0a
 * Microsoft Excel 5.0c
 * Microsoft Excel 95 Standard Edition

-



This article was previously published under Q149998





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 professionals 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:  Insert both a Module and a 4.0 Macro sheet in a Microsoft Excel version 5.0 or 7.0 workbook.  Place the following code on the Module sheet: Sub Test Msgbox "This is a test" End Sub  Save the workbook as VBA_XLM.xls. On the 4.0 Macro sheet, place the following code:

A1: Test1

A2: =RUN(VBA_XLM.xls!test)

A3: =RETURN

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

 On the Insert menu, point to Name, and then click Define.</li> In the Define Name dialog box, click Test1 in the Names In Workbook list.</li> Under Macro, click Command.

The Category list defaults to User Defined.</li> Click Add, and then click OK.</li></ol> </li> Save the workbook.</li> On the Tools menu, click Macro.</li> In the Macro dialog box, click Test1, and then click Run.

You should receive a dialog box with the message "This is a test."</li></ol>

<div class="references_section">