sound

  • Thread starter Thread starter pytelium
  • Start date Start date
P

pytelium

I want to produce a sound or beep when the contents of a cell become a
certain value,eg if h5 =10 then beep
 
Option Explicit

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, _
hModule As Long, _
ByVal dwFlags As Long) As Long

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("A1:H10")) Is Nothing Then
With Target
PlayWavFile "C:\Windows\Media\chimes.wav"
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

Public Function PlayWavFile(WavFile As String) As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
PlaySound WavFile, 0, SND_ASYNC Or SND_FILENAME
PlayWavFile = ""
End Function


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.





--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Back
Top