Microsoft KB Archive/125810

= Macro with OnEntry or ON.ENTRY Not Activated =

Article ID: 125810

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition
 * Microsoft Excel 95 Standard Edition
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q125810



SUMMARY
In Microsoft Excel, the Microsoft Visual Basic for Applications OnEntry property or the Microsoft Excel 4.0 ON.ENTRY macro function runs a macro when data is entered in any cell on a specified worksheet. Note, however, that you must first run the macro containing the OnEntry property or ON.ENTRY function in order for it to be effective.

To run the macro with the OnEntry property or ON.ENTRY function, use the appropriate procedure below to define an auto_open procedure or macro on the specified worksheet. The auto_open procedure should contain either the OnEntry property or the ON.ENTRY function, and it should specify another macro that will be run when you enter data on the worksheet.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.

Microsoft Excel 5.0 or Later
  In a new Visual Basic module, enter the following: Sub Auto_Open Worksheets("Sheet1").OnEntry = "Test" End Sub

Sub Test MsgBox "A key was pressed." End Sub  Save the workbook as Test.xls, and close it.

When you open Test.xls, the auto_open macro will run automatically. When you enter data in any cell on Sheet1 of Test.xls, a message box is displayed.

Microsoft Excel version 4.0
  Enter the following in a new Microsoft Excel 4.0 macro sheet:      A1: Auto_Open                       B1: Test A2: =ON.ENTRY("SHEET1.XLS","test") B2: =ALERT("A key was pressed.") A3: =RETURN                      B3: =RETURN  Define cells A1 and B1 as command macros by clicking Define Name on the Formula menu. Save the macro sheet as On_entry.xlm.</li> Select any cell on a worksheet, and click Define Name on the Formula menu. In the Name box, type Auto_Open .</li> In the Refers To box, type a reference to the macro sheet and the cell containing the ON.ENTRY function. For example, type =On_entry.xlm!$A$1 .</li> Save the worksheet as On_entry.xlm.</li></ol>

When the On_entry.xls worksheet is opened, On_entry.xlm will also be opened, and the Auto_Open macro will be run. When you enter data in any cell on On_entry.xls, an alert box will be displayed.

<div class="references_section">