Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Roy
 
Posts: n/a
Default How can I play a .WAV file in Excel if a condition is met?

Can anyone please tell me how I can play a .WAV file in Excel if a condition
is met using the IF statement?


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bernie Deitrick
 
Posts: n/a
Default How can I play a .WAV file in Excel if a condition is met?

Roy,

Right click the sheet tab, select "View Code", and paste this code into the window that appears.
This assumes that you have a formula like

=IF(C1="Test", "True", "False")

in cell A1 of that sheet.

Private Sub Worksheet_Calculate()
If Range("A1").Value = "True" Then
PlayMySound ("C:\Windows\Media\Jungle Error.wav")
End If
End Sub

In a regular codemodule in the same workbook, paste this code:

Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (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 MVP


"Roy" wrote in message
...
Can anyone please tell me how I can play a .WAV file in Excel if a condition
is met using the IF statement?




  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Roy
 
Posts: n/a
Default How can I play a .WAV file in Excel if a condition is met?

Bernie,
Thanks for that, how do I copy the second piece of code into a regular
codemodule?

Roy

"Bernie Deitrick" wrote:

Roy,

Right click the sheet tab, select "View Code", and paste this code into the window that appears.
This assumes that you have a formula like

=IF(C1="Test", "True", "False")

in cell A1 of that sheet.

Private Sub Worksheet_Calculate()
If Range("A1").Value = "True" Then
PlayMySound ("C:\Windows\Media\Jungle Error.wav")
End If
End Sub

In a regular codemodule in the same workbook, paste this code:

Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (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 MVP


"Roy" wrote in message
...
Can anyone please tell me how I can play a .WAV file in Excel if a condition
is met using the IF statement?





  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bernie Deitrick
 
Posts: n/a
Default How can I play a .WAV file in Excel if a condition is met?

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

Bernie,
Thanks for that, how do I copy the second piece of code into a regular
codemodule?

Roy



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
Stop excel from dropping the 0 in the beginning of a number? Rosewood Setting up and Configuration of Excel 12 April 4th 23 02:12 PM
Insert & link a graphic file in Excel 2003 -- updatable pictures! ODI Excel Discussion (Misc queries) 7 November 14th 05 02:36 PM
How do I unlock FILE access? rcmodelr Excel Discussion (Misc queries) 7 November 12th 05 09:55 PM
Reflecting info between an excel file and a word one or two excel file. Starriol Links and Linking in Excel 0 November 3rd 05 01:49 PM
Very slow in opening Excel 97 file in Excel 2003 S M Setting up and Configuration of Excel 0 October 22nd 05 07:32 PM


All times are GMT +1. The time now is 06:42 PM.

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

About Us

"It's about Microsoft Excel"