View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
sl[_2_] sl[_2_] is offline
external usenet poster
 
Posts: 3
Default playing sounds from cell value

that was a great help

thanks very much..


"ste mac" wrote in message
om...
Hi SL,
This is the code I use to play a sound file in excel, as long as the
soundfile is in the same workbook folder it will play it, just change
'yourwavfile' to whatever sound file you want to play...

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

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Sub RunSLmacro()
WAVFile = "yourwavfile.wav"
WAVFile = ThisWorkbook.Path & "\" & WAVFile
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)

End Sub

As for playing it when a cell value changes you could do something like:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then ' change you cell here

RunSLmacro

End If

End Sub

hope this helps...

seeya ste