How-To

How to Ring an Alarm in Excel

Would you like to hear an audio notification when your Excel data hits certain values? Here’s how to ring an alarm in Excel.

Excel spreadsheets allow you to quickly and easily see important values within your data. You can use conditional formatting in Excel, for example, to change the color of a cell depending on its value.

A visual indication is useful, but if the cell in question is on another sheet or off the edge of your current view, then you’re not going to notice the change. Wouldn’t it be useful if you could get Excel to make a sound when certain criteria are met?

The good news is that it is possible to do, although you’ll need to dip your toe into the world of Visual Basic to do so. Thankfully, you won’t need any programming skills to get this to work; you can simply copy and paste the code below.

Here’s how to ring an alarm in Excel.

How to Play a System Sound to Ring an Alarm in Excel

You can make Excel play a system sound with just a few lines of Visual Basic. You can then trigger this sound based on the value of a cell.

To play a system sound in Excel:

    1. Launch Microsoft Visual Basic for Applications by using the keyboard shortcut Alt+F11.
    2. Go to Insert > Module.
      excel vba insert module
    3. Enter the following code:
      Function MakeABeep() as String
          Beep
          MakeABeep = “”
      End Function

      excel makeabeep

    4. Click the Save icon.
      excel save
    5. Click on the Save as Type drop-down and select Excel Macro-Enabled Workbook. Your file needs to be saved in this format for the sound to play.
      excel macro enabled workbook
    6. Save your workbook.
    7. Close the Microsoft Visual Basic for Applications window by clicking the X in the top-right hand corner of the window.
      excel close vba
    8. To test your beep, type the following into any cell: =MakeABeep()
      excel test sound
    9. Press Enter, and you should hear a system sound.

How to Play a Custom Sound in Excel Using Visual Basic

You can also get Excel to play a specific sound file if you prefer to choose your own sound rather than playing the default system beep.

To play a custom sound in Excel:

  1. Launch Microsoft Visual Basic for Applications by pressing Alt+F11.
  2. Click Insert > Module.
    excel vba insert module
  3. Enter the following code:
    #If Win64 Then
        Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _
            Alias "PlaySoundA" (ByVal lpszName As String, _
            ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean
    #Else
        Private Declare Function PlaySound Lib "winmm.dll" _
            Alias "PlaySoundA" (ByVal lpszName As String, _
            ByVal hModule As Long, ByVal dwFlags As Long) As Boolean
    #End If
    Const SND_SYNC = &H0
    Const SND_ASYNC = &H1
    Const SND_FILENAME = &H20000
    Function AlarmSound() As String
        Call PlaySound("C:\Users\adam\Downloads\alarm.wav", _
          0, SND_ASYNC Or SND_FILENAME)
        AlarmSound = ""
    End Function

  4. Replace “C:\Users\adam\Downloads\alarm.wav” with the file location of the sound file you want to use. The easiest way to get the full file path is to navigate to the file in Windows Explorer, right-click on it, and select Copy as Path.
    windows copy as path
  5. Close the Microsoft Visual Basic for Applications window.
    excel close vba
  6. Test your sound by typing the following into any cell: =AlarmSound()
    excel test alarm sound
  7. Press Enter, and your sound should play.

How to Trigger a Sound to Ring an Alarm in Excel

Now that you have set up your beep or alarm sound, the final stage is to trigger these sounds when needed. There are many different ways you can choose to trigger your alarm. Here is an example of how to use your sound in an IF statement.

To play an alarm when a value reaches a certain level:

  1. Select an empty cell.
  2. Type: =IF(
    excel if function
  3. Click the cell you want to monitor the value of.
  4. Type: > followed by the value you want to trigger the alarm.
    excel if greater than
  5. Now type a comma, then MakeaBeep() or AlarmSound().
    excel if makeabeep
  6. Type another comma, then type: “”)
    excel if formula
  7. Press Enter.
    Now when the cell you are monitoring exceeds the value you set, your alarm will sound. You can test this by typing a value above your threshold into the relevant cell.

Unleash the Power of Excel

Learning to ring an alarm in Excel requires you to use Visual Basic. Using Visual Basic allows you to get Excel to do things far beyond its usual scope. However, it requires a reasonable knowledge of the programming language and how it works with Excel.

Excel can do plenty of things without the need for using Visual Basic. You can record macros in Excel that will replay a series of actions. Once created, you can save your macros to use in other spreadsheets. You can also create Excel formulas using the many built-in functions in Excel, such as VLOOKUP, TRUNC, or any of the many other useful functions.

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

 

To Top