PDA

View Full Version : Solved: Play 2 Wav in VBA



Emoncada
03-02-2012, 10:34 AM
I have a script that plays a wav when a msg box comes up.
How can I make it play 2 wav files back to back?

Option Explicit

Private Declare Function sndPlaySound32 Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName _
As String, ByVal uFlags As Long) As Long

Private Sub Worksheet_Change(ByVal Target As Range)
Dim PlaySound As Boolean

If InStr(1, Range("A2").Value, "#") Then
Application.ScreenUpdating = False

PlaySound = True

If PlaySound Then
Call sndPlaySound32("C:\housprob.wav", 1)

'This is where the other sound is
' Call sndPlaySound32("C:\DingDong.wav",1)

End If

MsgBox "Invalid Character Entered", vbOKOnly, "Invalid Character"

Range("A2").Select


Application.ScreenUpdating = True





I would like for them to play back to back

georgiboy
03-02-2012, 10:53 AM
Sorry if this is useless but you could join the wav files together using audio software, just a different angle.

Emoncada
03-02-2012, 11:16 AM
Ok I was able to make it work thanks to another post I found.

Incase anyone needs it

Public Declare Function PlaySound Lib "winmm.dll" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_LOOP = &H8
Const SND_NOSTOP = &H10
Dim RunPause As Boolean
Sub Sound_1()
Call PlaySound(ThisWorkbook.Path & "\one.wav", 0&, SND_SYNC)
End Sub
Sub Sound_123_sync()
Call PlaySound(ThisWorkbook.Path & "\one.wav", 0&, SND_SYNC)
Call PlaySound(ThisWorkbook.Path & "\two.wav", 0&, SND_SYNC)
Call PlaySound(ThisWorkbook.Path & "\three.wav", 0&, SND_SYNC)
End Sub

Using this in a Module helped me get it to work for me tweeking it a little.

Hopes it helps others