XL: Macro with OnEntry or ON.ENTRY() Not Activated

Last reviewed: February 3, 1998
Article ID: Q125810
The information in this article applies to:
  • Microsoft Excel for Windows, versions 4.0, 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 4.0, 5.0, 5.0a
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel 97 for Windows
  • Microsoft Excel 98 Macintosh Edition

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, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and 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 needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

Microsoft Excel 5.0 or Later

  1. 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
    
    

  2. 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

  1. 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()
    
    

  2. Define cells A1 and B1 as command macros by clicking Define Name on the Formula menu.

  3. Save the macro sheet as On_entry.xlm.

  4. Select any cell on a worksheet, and click Define Name on the Formula menu. In the Name box, type "Auto_Open" (without the quotation marks).

  5. 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" (without the quotation marks).

  6. Save the worksheet as On_entry.xlm.

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.

REFERENCES

"Microsoft Excel Function Reference," version 4.0, page 302


Additional query words: 4.00 4.00a 5.00 5.00a 5.00c 7.00 7.00a XL98 XL97
XL7 XL5 XL4
Keywords : kbcode kbprg PgmEvnt PgmHowto
Version : WINDOWS:4.0,5.0,5.0c,7.0,7.0a,97; MACINTOSH:4.0,5.0,5.0a,98
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


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 3, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.