Patrick.
Here is an easier version to do this using a user defined function. Place this function in some cell. The arguments are:
1. Any expression which can be evaluated as TRUE or FALSE. This would include any Excel function of a formula of various functions and values which you could evaluate as either true or false.
2. The path of the sound file you want to play whenever the Expression evaluates to TRUE.
3. The stop range. Any range that you will select to end the alarm.
Example:
=sta(MAX(B:B)>20, "C:\WINNT\MEDIA\TADA.WAV",A:A)
The function will evaluate to TRUE and sound the alarm when any value in column B is greater than 20.
"C:\WINNT\MEDIA\TADA.WAV" is the wav file which will play in a continuous loop until...
You select a cell within the stop range which is Column A (A:A = the last argument). Change the file path argument to suit.
An immediately apparent flaw would be if you happen to have column A selected. The sound will not play. So make sure you don't have the stop range selected. There are a hundred other ways to stop the wave file but this is just to give you some ideas.
This will only work with a single STA function as only one timer will be allowed to run at any given time. You could change this by adding an argument which would take a "priority" value, so to speak, and then cache your calculations. You could also use the WorkSheet_Change event but I thought this to be a bit more flexible and easier to work with.
Copy all of the code into a standard module. Use the function. Download the example below if you have any problems.
<font color="#202020" size="3" face="Courier New"><pre>
<font face="Courier New" size="2" color="#0000A0">Option Explicit</font>
<font face="Courier New" size="2" color="#0000A0">Private</font> <font face="Courier New" size="2" color="#0000A0">Declare</font> <font face="Courier New" size="2" color="#0000A0">Function</font> PlaySound _
<font face="Courier New" size="2" color="#0000A0">Lib</font> "winmm.dll" _
<font face="Courier New" size="2" color="#0000A0">Alias</font> "PlaySoundA" ( _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> lpszName
<font face="Courier New" size="2" color="#0000A0">As String</font>, _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> hModule
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>, _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> dwFlags
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font> _
)
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>
<font face="Courier New" size="2" color="#0000A0">Private</font> <font face="Courier New" size="2" color="#0000A0">Declare</font> <font face="Courier New" size="2" color="#0000A0">Function</font> SetTimer _
<font face="Courier New" size="2" color="#0000A0">Lib</font> "user32" ( _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> hwnd
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>, _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> nIDEvent
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>, _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> uElapse
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>, _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> lpTimerFunc
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font> _
)
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>
<font face="Courier New" size="2" color="#0000A0">Private</font> <font face="Courier New" size="2" color="#0000A0">Declare</font> <font face="Courier New" size="2" color="#0000A0">Function</font> KillTimer _
<font face="Courier New" size="2" color="#0000A0">Lib</font> "user32" ( _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> hwnd
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>, _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> nIDEvent
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font> _
)
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>
<font face="Courier New" size="2" color="#0000A0">Private</font> lngTimerID
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>
<font face="Courier New" size="2" color="#0000A0">Private</font> rngKillWav
<font face="Courier New" size="2" color="#0000A0">As</font> Range
<hr size=1 style="verticalAlign=top;">
<font face="Courier New" size="2" color="#0000A0">Public</font> <font face="Courier New" size="2" color="#0000A0">Function</font> STA( _
Expression
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Boolean</font>, _
Wav_Path
<font face="Courier New" size="2" color="#0000A0">As String</font>, _
Wav_Kill
<font face="Courier New" size="2" color="#0000A0">As</font> Range _
)
<font face="Courier New" size="2" color="#0000A0">As String</font>
<font face="Courier New" size="2" color="#009900"> 'do not edit and use a DoEvents/DoLoop to wait for a selection change.</font>
<font face="Courier New" size="2" color="#009900"> 'you will need a reboot. The timer is more stable</font>
<font face="Courier New" size="2" color="#0000A0">If</font> Expression
<font face="Courier New" size="2" color="#0000A0">Then</font> PlaySound Wav_Path,
<font face="Courier New" size="2" color="#0000A0">ByVal</font> 0&, &H20000
<font face="Courier New" size="2" color="#0000A0">Or</font> &H1
<font face="Courier New" size="2" color="#0000A0">Or</font> &H8
<font face="Courier New" size="2" color="#009900"> 'change "STA" to whatever or nothing at all.</font>
STA = "STA"
<font face="Courier New" size="2" color="#009900"> 'this is the module level range which will interupt the sound loop</font>
<font face="Courier New" size="2" color="#0000A0">Set</font> rngKillWav = Wav_Kill
<font face="Courier New" size="2" color="#009900"> 'this is only set up to work with one single function. You would need to</font>
<font face="Courier New" size="2" color="#009900"> 'cache any other calculations and run them after each timer process has ended</font>
<font face="Courier New" size="2" color="#0000A0">If</font> lngTimerID = 0
<font face="Courier New" size="2" color="#0000A0">Then</font>
lngTimerID = SetTimer(0, 0, 10,
<font face="Courier New" size="2" color="#0000A0">AddressOf</font> RunProc)
<font face="Courier New" size="2" color="#0000A0">End If</font>
<font face="Courier New" size="2" color="#0000A0">End</font> <font face="Courier New" size="2" color="#0000A0">Function</font>
<hr size=1 style="verticalAlign=top;">
<font face="Courier New" size="2" color="#0000A0">Private</font> <font face="Courier New" size="2" color="#0000A0">Sub</font> RunProc(ByVal hwnd
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>, _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> uint1
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>, _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> nEventId
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>, _
<font face="Courier New" size="2" color="#0000A0">ByVal</font> dwParam
<font face="Courier New" size="2" color="#0000A0">As</font> <font face="Courier New" size="2" color="#0000A0">Long</font>)
<font face="Courier New" size="2" color="#0000A0">On</font> <font face="Courier New" size="2" color="#0000A0">Error</font> <font face="Courier New" size="2" color="#0000A0">Resume</font> <font face="Courier New" size="2" color="#0000A0">Next</font>
<font face="Courier New" size="2" color="#009900"> 'if the correct range is selected, the sound loop and timer will end.</font>
<font face="Courier New" size="2" color="#0000A0">If</font> <font face="Courier New" size="2" color="#0000A0">Not</font> Intersect(Selection, rngKillWav)
<font face="Courier New" size="2" color="#0000A0">Is</font> <font face="Courier New" size="2" color="#0000A0">Nothing</font> <font face="Courier New" size="2" color="#0000A0">Then</font>
PlaySound vbNullString, 0, 0
<font face="Courier New" size="2" color="#0000A0">Set</font> rngKillWav =
<font face="Courier New" size="2" color="#0000A0">Nothing</font>
KillTimer 0, lngTimerID
lngTimerID = 0
<font face="Courier New" size="2" color="#0000A0">End If</font>
<font face="Courier New" size="2" color="#0000A0">End</font> <font face="Courier New" size="2" color="#0000A0">Sub</font> <hr size=1 style="verticalAlign=top;">
</pre></font>
Google Search<text> - </text>
Email TsTom<text> - </text>
Where do I put this code?<text> - </text>
Copy Code to your Clipboard<text> - </text>
Download Example
<pre> If you need further information pertaining to the above code, click on the term in question.
Many, but not all, are links to MSDN. If the downloaded file does not behave correctly in your
browser, then right click the link, choose "Save target as" and download to your hard-drive.
Tom</pre>