ExcelFailure
Board Regular
- Joined
- Mar 6, 2013
- Messages
- 74
Hello and thanks,
Does anyone know what is wrong with this code? It comes up with a compile error.
Thanks again
Does anyone know what is wrong with this code? It comes up with a compile error.
Thanks again
Code:
Private Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Private Sub Worksheet_calculate(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("I2")
If Not Application.Intersect(KeyCells, Target) _
Is Nothing Then
PlayWavFile "c:\tada.wav", False
End If
End Sub
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
End If
End Sub