Can anyone please tell me how I can play a .WAV file in Excel if a condition
is met using the IF statement?
Roy,
Right click the sheet tab, select quot;View Codequot;, and paste this code into the window that appears.
This assumes that you have a formula like
=IF(C1=quot;Testquot;, quot;Truequot;, quot;Falsequot;)
in cell A1 of that sheet.
Private Sub Worksheet_Calculate()
If Range(quot;A1quot;).Value = quot;Truequot; Then
PlayMySound (quot;C:\Windows\Media\Jungle Error.wavquot;)
End If
End Sub
In a regular codemodule in the same workbook, paste this code:
Declare Function sndPlaySound32 Lib quot;winmm.dllquot; Alias _
quot;sndPlaySoundAquot; (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Sub PlayMySound(myFileName As String)
Call sndPlaySound32(myFileName, 0)
End Sub
HTH,
Bernie
MS Excel MVPquot;Royquot; gt; wrote in message
...
gt; Can anyone please tell me how I can play a .WAV file in Excel if a condition
gt; is met using the IF statement?
gt;
gt;
Bernie,
Thanks for that, how do I copy the second piece of code into a regular
codemodule?
Roy
quot;Bernie Deitrickquot; wrote:
gt; Roy,
gt;
gt; Right click the sheet tab, select quot;View Codequot;, and paste this code into the window that appears.
gt; This assumes that you have a formula like
gt;
gt; =IF(C1=quot;Testquot;, quot;Truequot;, quot;Falsequot;)
gt;
gt; in cell A1 of that sheet.
gt;
gt; Private Sub Worksheet_Calculate()
gt; If Range(quot;A1quot;).Value = quot;Truequot; Then
gt; PlayMySound (quot;C:\Windows\Media\Jungle Error.wavquot;)
gt; End If
gt; End Sub
gt;
gt; In a regular codemodule in the same workbook, paste this code:
gt;
gt; Declare Function sndPlaySound32 Lib quot;winmm.dllquot; Alias _
gt; quot;sndPlaySoundAquot; (ByVal lpszSoundName As String, _
gt; ByVal uFlags As Long) As Long
gt;
gt; Sub PlayMySound(myFileName As String)
gt; Call sndPlaySound32(myFileName, 0)
gt; End Sub
gt;
gt; HTH,
gt; Bernie
gt; MS Excel MVP
gt;
gt;
gt; quot;Royquot; gt; wrote in message
gt; ...
gt; gt; Can anyone please tell me how I can play a .WAV file in Excel if a condition
gt; gt; is met using the IF statement?
gt; gt;
gt; gt;
gt;
gt;
gt;
Roy,
Copy the code, press Alt-F11 from Excel to open the VBEditor, press F4 to open the project explorer,
select your workbook, then use Insert / Module command to insert a regular codemodule. Then paste
the code into the window to the (usually) right.
HTH,
Bernie
MS Excel MVP
gt; Bernie,
gt; Thanks for that, how do I copy the second piece of code into a regular
gt; codemodule?
gt;
gt; Roy
- Nov 03 Mon 2008 20:47
How can I play a .WAV file in Excel if a condition is met?
close
全站熱搜
留言列表
發表留言
留言列表

