Excel: Worksheet Formula to Beep and Display an Alert Box

Last reviewed: July 12, 1996
Article ID: Q86011
The information in this article applies to:
  • Microsoft Excel for Windows, versions 3.0, 4.0, 4.0a, 5.0
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel for Windows NT, version 5.0

SUMMARY

The following formulas, when entered on a spreadsheet, will produce a beep and display an alert box if the specified condition occurs.

   16-bit versions of Microsoft Excel (3.x, 4.x, 5.x for Windows)
   --------------------------------------------------------------
   =IF(CONDITION,TEXT(CALL("USER.EXE","MessageBeep",">H",0)+CALL("USER
   .EXE","MessageBox","HHCCH",0,"MESSAGE","TITLE",),""),"")

   32-bit versions of Microsoft Excel (5.0 for Windows NT, 7.0)
   ------------------------------------------------------------
   =IF(CONDITION,TEXT(CALL("USER32","MessageBeep",">H",0)+CALL("USER32",
   "MessageBoxA","HHCCH",0,"MESSAGE","TITLE",),""),"")

Where:
  • CONDITION is a valid conditional statement, such as A1>5.
  • "MESSAGE" is a text string which will appear inside the alert box that will be displayed when the condition is met.
  • "TITLE" is a text string which will appear inside the title bar of the alert box that will be displayed when the condition is met.

MORE INFORMATION

The CALL statements call routines are part of the Windows DLL files USER.EXE (16-bit) and USER32.DLL (32-bit). Because the CALL statement can be used in this form on a Microsoft Excel worksheet it is not necessary to use a macro sheet or Visual Basic module.

The message in the alert box may contain multiple lines by typing the first line of MESSAGE text and then pressing ENTER while holding down the ALT key.

REFERENCES

"Microsoft Excel Function Reference," version 3.0, pages 24-25, 125-126 and 234-235

"Microsoft Excel Function Reference," version 4.0, pages 42-43, 225-226 and 431-432

Microsoft Windows Software Developers Kit


KBCategory: kbusage
KBSubcategory:

Additional reference words: 3.0 3.00 4.0 4.00 sdk 5.00


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