Playing sound in VBA

P

Pete

Hi
Somebody please help.
I had a look at John Walkenbach's site and copied off some code to play a
wave file.
I run Excel 2003 under Windows XP Home
I can play the different sounds perfectly when clicking on the various wave
files (it automatically launches Windows Media Player)

However when I run the code below I get the same dull 'clunck' no matter
what wave file I put in (WAVFile) - its always the same!
I did do a search for "winmm.dll" but could not locate it on my system. Is
this the problem or am I doing something else wrong?
Is there perhaps a library that I need to tick off?
I also tried running the code on another PC with the same result.

Desperate Pete

'=============================
Option Explicit
Private 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_FILENAME = &H20000

Sub PlayWAV()
Dim WAVFile As String
If Not Application.CanPlaySounds Then
MsgBox "Sorry, sound is not supported on your system."
Else
WAVFile = "C:\Windows\Media\Microsoft Office 2000\Chimes.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End If
End Sub
'============================
 
B

Bob Phillips

Maybe a long shot, but try this slight variation

Option Explicit
Private 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_FILENAME = &H20000

Sub PlayWAV()
Dim WAVFile As String
If Not Application.CanPlaySounds Then
MsgBox "Sorry, sound is not supported on your system."
Else
WAVFile = "C:\Windows\Media\Microsoft Office 2000\Chimes.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Alarm 2 2
playing wma files 2
Playing wavfiles from excel 3
Assign a sound to a variable 19
Wavfile playing trubcated 3
sound 4
Run-time error question 0
Sound repeats unending until closing workbook 2

Top