Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Conditionally Making a Sound.
by Allen Wyatt
(last updated June 8, 2018)
Ken knows how to create conditional formats in Excel. What he really wants to do, however, is have Excel make an audible sound (a beep or whatever) if the conditions are met.
There is no way to do this without resorting to using macros. If you just want to make a beep sound, you can use something like this:
Function BeepMe() As String Beep BeepMe = "" End Function
All this user-defined function does is to play a sound (which will vary depending on the system you are using) and then return an empty string. You can use the function in your worksheet in this manner:
If you want to play some sound other than the default system beep, you'll need to use the Windows API PlaySound function. The following code creates a user-defined function that will play the default "tada" sound so prevalent in many versions of Windows.
Private Declare Function PlaySound Lib "winmm.dll" _ Alias "PlaySoundA" (ByVal lpszName As String, _ ByVal hModule As Long, ByVal dwFlags As Long) As Long Const SND_SYNC = &H0 Const SND_ASYNC = &H1 Const SND_FILENAME = &H20000 Function SoundMe() As String Call PlaySound("c:\windows\media\tada.wav", _ 0, SND_ASYNC Or SND_FILENAME) SoundMe = "" End Function
This function can be called the same as the previous example:
If you want to play a different WAV file, simply change the file specification in the SoundMe function.
Note that the code needs to be entered in an inserted module in the VBA Editor in order for the function to work properly.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (5834) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Conditionally Making a Sound.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
If you want to highlight cells that contain certain characters, you can use the conditional formatting features of Excel ...Discover More
Conditional formatting rules can be used to adjust the way in which information is displayed in Excel, such as the text ...Discover More
Conditional formatting can be used to draw attention to all sorts of data based upon the criteria you specify. Here's how ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.