Excel: Worksheet Formula to Beep and Display an Alert Box

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

Additional query words: 3.0 4.0 sdk

Keywords :
Version : 3.00 4.00 4.00a 5.00 7.00
Platform : WINDOWS
Issue type :


Last Reviewed: March 25, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.