Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. 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 November 17, 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, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Conditionally Making a Sound.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Need to have your worksheet printout start on a new page every time a value in a column changes? There are a couple of ...Discover More
Conditional formatting is a powerful tool you can use to dynamically adjust the formatting of your worksheet. This tip ...Discover More
Want to know where duplicates are in a list of names? There are a couple of ways you can go about identifying the ...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.