Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can u play sound from vba? 1

Status
Not open for further replies.

nurun

Technical User
Apr 26, 2002
8
GB
Can anyone please tell me how I can make a wav file play from vba code given a condition.
 
By using the PlaySound API function.

Here is how, this piece of code was taken from John Walkenbach website :
Code:
Private Declare Function PlaySound Lib "winmm.dll" _  Alias "PlaySoundA" (ByVal lpszName As String, _  ByVal hModule As Long, ByVal dwFlags As Long) As Long

Function Alarm(Cell, Condition)    
Dim WAVFile As String    
Const SND_ASYNC = &H1    
Const SND_FILENAME = &H20000    
On Error GoTo ErrHandler    
If Evaluate(Cell.Value & Condition) Then        
WAVFile = ThisWorkbook.Path & "\sound.wav" 'Edit this statement        
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)        
Alarm = True        
Exit Function    
End If
ErrHandler:    
Alarm = False
End Function

LSTAN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top