View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Hotbird[_4_] Hotbird[_4_] is offline
external usenet poster
 
Posts: 5
Default HOW TO PLAY SOUND.WAV FILES SIMULTANEOUSLY UNDER EXCEL

I have a requirement to trigger 3 sound effects during execution of an Excel
macro. When the Workbook opens, Function Keys are assigned to each Sound
procedure as follows:

Option Explicit
Private Sub Workbook_Open()

' ASSIGN FUNCTION KEYS

Application.OnKey "{F1}", "Sound1"
Application.OnKey "{F2}", "Sound2"
Application.OnKey "{F3}", "Sound3"

End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)

' RESET FUNCTION KEYS

Application.OnKey "{F1}"
Application.OnKey "{F2}"
Application.OnKey "{F3}"

End Sub

The following Windows API function declarations appear in the Module code:

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

Private Const SND_ASYNC = &H1
Private Const SND_FILENAME = &H20000

The individual Sound procedures a

Public Sub Sound1()

Call PlaySound(ThisWorkbook.Path & "\sound1.wav", 0&, SND_ASYNC Or
SND_FILENAME)

End Sub
Private Sub Sound2()

Call PlaySound(ThisWorkbook.Path & "\sound2.wav", 0&, SND_ASYNC Or
SND_FILENAME)

End Sub
Private Sub Sound3()

Call PlaySound(ThisWorkbook.Path & "\sound3.wav", 0&, SND_ASYNC Or
SND_FILENAME)

End Sub

When F1 is pressed, sound1.wav file plays, and similarly when F2 and F3 are
pressed, the corresponding sound2.wav and sound3.wav files play. So far, so
good. If a second sound file is triggered before the first one has finished
playing, the first one is abandoned, and the second plays alone. What I want
is to allow more than one sound file to be triggered and play to completion
without being interrupted.

Is there way of achieving this, perhaps involving a different Windows API
function declaration? Or would 3 Sound Cards be needed to play the wav files
completely independently?