![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Posts: 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 |
|
|
|
|
|
#2 |
|
New Member
Join Date: Apr 2002
Location: Kansas City, MO
Posts: 14
|
=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. |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
|
Datastream
which version of excel does this function appear in ? it's not in '97... |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
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 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|