Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem with playing sound code


Hello,

I have this code from j-walk.com website (The Alarm Function).

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

I found a wav clip on my computer c:\windows\media\ringin.wav

I don't know how to place this path in the code, nor reference a cell
to evaluate.

Need some help on this one,
Thanks, EMoe


--
EMoe
------------------------------------------------------------------------
EMoe's Profile: http://www.excelforum.com/member.php...o&userid=23183
View this thread: http://www.excelforum.com/showthread...hreadid=384447

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Problem with playing sound code

Paste the below code to a standard module. As an example, in any cell except
A1 paste the following formula:
=Alarm(A1, "=100")
If sound is enabled on your computer then when the value in A1 =100 then
you should hear a "ding" sound. Works for me. Of course, you can make it
refer to any cell (except the cell containing the formula) and any condition
you like.

Regards,
Greg

Option Explicit
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 = "c:\windows\media\ringin.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
Alarm = True
Exit Function
End If
ErrHandler:
Alarm = False
End Function

"EMoe" wrote:


Hello,

I have this code from j-walk.com website (The Alarm Function).

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

I found a wav clip on my computer c:\windows\media\ringin.wav

I don't know how to place this path in the code, nor reference a cell
to evaluate.

Need some help on this one,
Thanks, EMoe


--
EMoe
------------------------------------------------------------------------
EMoe's Profile: http://www.excelforum.com/member.php...o&userid=23183
View this thread: http://www.excelforum.com/showthread...hreadid=384447


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Problem with playing sound code

Further to my post, instead of just having the cell containing the formula
return either True of False, you can make it return a suitable text message.
Be advised that this is the first time I've used this myself. But I hav't
found a problem so far. Example with text message:

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 = "c:\windows\media\ringin.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
Alarm = "Limit of 100 reached or exceeded !!!"
Else
Alarm = "Current value < 100"
End If
Exit Function
ErrHandler:
Alarm = "Error: " & Err.Description
'Alarm = False
End Function

"Greg Wilson" wrote:

Paste the below code to a standard module. As an example, in any cell except
A1 paste the following formula:
=Alarm(A1, "=100")
If sound is enabled on your computer then when the value in A1 =100 then
you should hear a "ding" sound. Works for me. Of course, you can make it
refer to any cell (except the cell containing the formula) and any condition
you like.

Regards,
Greg

Option Explicit
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 = "c:\windows\media\ringin.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
Alarm = True
Exit Function
End If
ErrHandler:
Alarm = False
End Function

"EMoe" wrote:


Hello,

I have this code from j-walk.com website (The Alarm Function).

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

I found a wav clip on my computer c:\windows\media\ringin.wav

I don't know how to place this path in the code, nor reference a cell
to evaluate.

Need some help on this one,
Thanks, EMoe


--
EMoe
------------------------------------------------------------------------
EMoe's Profile: http://www.excelforum.com/member.php...o&userid=23183
View this thread: http://www.excelforum.com/showthread...hreadid=384447


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem with playing sound code


This is great.

"New Test"!!!

Is there a way to loop this code so that the sound will play over and
over until the cell condition becomes false again?

Thanks,
EMoe


--
EMoe
------------------------------------------------------------------------
EMoe's Profile: http://www.excelforum.com/member.php...o&userid=23183
View this thread: http://www.excelforum.com/showthread...hreadid=384447

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I keep the ding sound from playing when a message appears? Quinn1984 Excel Discussion (Misc queries) 2 September 12th 07 01:04 PM
Playing a sound file from entry in cell NG99 Excel Discussion (Misc queries) 2 January 31st 07 12:27 AM
Help Playing a sound if a cell's value chjanges as a result of a calculation Syd Excel Discussion (Misc queries) 1 September 2nd 06 01:36 AM
playing sound??? tess457[_6_] Excel Programming 2 October 20th 04 11:50 AM
Playing a sound base on cell value Mike[_58_] Excel Programming 4 November 30th 03 03:53 AM


All times are GMT +1. The time now is 02:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"