sound

timaru

New Member
Joined
May 6, 2002
Messages
1
How do i get excel to play a wav file if a cell satisfies a certain condition??
For example, if a1 > 25 then play
beep.wav

Thanks for any help
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
=Alarm(A1,">=1000")
The sound will play when the value in cell A1 is greater than or equal to 1,000.

=Alarm(C12,"<0")
The sound will play when the value in cell C12 is negative.

OR VBA EXAMPLE:

'Windows API function declaration
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long


Function Alarm(Cell, Condition)
Dim WAVFile As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
On Error GoTo ErrHandler
If Evaluate(Cell.Value & Condition) Then
WAVFile = ThisWorkbook.Path & "sound.wav" 'Edit this statement
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
Alarm = True
Exit Function
End If
ErrHandler:
Alarm = False
End Function

If you do not change the path of the sound file, it will just use a default sound. The program will first look for the file in the same path as the workbook, if not there, default sound will play. Unless you put the correct path if the sound is somewhere else.

Enjoy.
 
Upvote 0
Chris,

The UDF Alarm is posted below his explanation. There's no built in Alarm function in Excel 2000 either (and presumably not XP)

EDIT - However, on re-reading the post it does imply that there is a non-VBA and a VBA way of doing it - hmmmmmmm...let's see :)

Cheers,
Dan
This message was edited by dk on 2002-05-08 12:41
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top