Excel/playing a sound
Is the following possible? I have a timer in cell J9. When the time reaches 10 seconds, I would like the soundfile at this address to play C:\sound.wav.
Is this possible using VBA?
When I place this code into the worksheet I get an error message along the lines of "ambiguous code...:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("J9") > Range("G4") Then PlayWavFile "C:\sound.wav", True
Could you tell me where I might have gone wrong?
Thanks in advance.
PlayWavFile isn't a standard VBA procedure, so must be a custom function - so it may be that the problem is there - ExcelTips give an example of a process that should work at
Itís easy to play soundfiles in WAV-format. You only need to know the filename of the sound you want to play,
and decide if you want the macro to wait while the sound plays or not. Here is an example:
Public Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Sub PlayWavFile(WavFileName As String, Wait As Boolean)
If Dir(WavFileName) = "" Then Exit Sub ' no file to play
If Wait Then ' play sound before running any more code
sndPlaySound WavFileName, 0
Else ' play sound while code is running
sndPlaySound WavFileName, 1
PlayWavFile "c:\foldername\soundfilename.wav", False
MsgBox "This is visible while the sound is playing..."
PlayWavFile "c:\foldername\soundfilename.wav", True
MsgBox "This is visible after the sound is finished playing..."
This hopefully gives you enough to get this resolved.
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here