|
|
|
|
|
|
Excel
|
Make a Sound When a Cell is Changed to a Certain Value
|
|
Ease of Use
|
Easy
|
Version tested with
|
2002
|
Submitted by:
|
Jacob Hilderbrand
|
Description:
|
This macro plays a wav file when any cell in a specified range is above a certain value.
|
Discussion:
|
You have several cells in a worksheet that calculate data. If these cells change to be greater than (or less than) a preset value, you want an immediate notification. This macro will play any wav file that you specify.
|
Code:
|
instructions for use
|
Option Explicit
Private Declare Function sndPlaySound32 Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName _
As String, ByVal uFlags As Long) As Long
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
Dim CheckRange As Range
Dim PlaySound As Boolean
Set CheckRange = Range("D5:G25")
For Each Cell In CheckRange
If Cell.Value > 10 Then
PlaySound = True
End If
Next
If PlaySound Then
Call sndPlaySound32("C:\windows\media\ding.wav", 1)
End If
End Sub
|
How to use:
|
- Copy the code above.
- Open Excel.
- Right-click the sheet tab on which you want the sound to play, and hit View-Code.
- Paste the code in the Code Window that opens to the right.
- Change the range for the CheckRange variable as needed.
- Change this line: { If Cell.Value > 10 Then } to indicate the value you want the code to work with.
- Change the path and the name of the wav file as needed.
- Close the Visual Basic Editor (Alt + Q or press the x in the top right corner).
|
Test the code:
|
- Change values in the worksheet. If a cell within CheckRange is changed to the appropriate value, the wav file plays.
|
Sample File:
|
Play Wav.ZIP 6.88KB
|
Approved by mdmackillop
|
This entry has been viewed 230 times.
|
|