Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Playing a WAV file in Excel 2002

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
chalky - 23 Jan 2006 14:09 GMT
I have the following code to play a WAV file in excel:

Sub PlayWavFile(WavFileName As String, Wait As Boolean)
If Dir(WavFileName) = "" Then Exit Sub ' no file to play
If Wait Then ' play sound before running any more code
sndPlaySound WavFileName, 0
Else ' play sound while code is running
sndPlaySound WavFileName, 1
End If
End Sub

where the file name is c:\accounts\05\temp\sound.wmv

I am really struggling to put this macro together, can anyone lay it
out in a slightly easier to follow format?

Thanks
chris

Signature

chalky

Tom Ogilvy - 23 Jan 2006 14:27 GMT
http://www.j-walk.com/ss/excel/tips/tip59.htm

John Walkenbach's page on playing a wav or midi sound.

Signature

Regards,
Tom Ogilvy

> I have the following code to play a WAV file in excel:
>
[quoted text clipped - 14 lines]
> Thanks
> chris
chalky - 23 Jan 2006 14:37 GMT
Ah thanks for this - no wonder it wasnt working, my system isnt
supporting it.

Thanks
Chris

Signature

chalky

chalky - 23 Jan 2006 16:28 GMT
I have managed to procure a laptop wherre this macro looks like it will
work fine.  The formula used is as follows:

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 PlayWAV()
WAVFile = "Noise-2.wav"
WAVFile = ThisWorkbook.Path & "\" & WAVFile
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub

However, when i run it i get the following error:

run-time error '453'

Can't find DLL entry point playsounda in winmm.dll

Any ideas?

Signature

chalky

Tom Ogilvy - 23 Jan 2006 19:06 GMT
Best I can tell you is that this worked fine for me:

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 PlayWAV()
'WAVFile = "Noise-2.wav"
WAVFile = "C:\WINDOWS\MEDIA\Chimes.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub

Windows XP Professional
Excel 2003

Signature

Regards,
Tom Ogilvy

> I have managed to procure a laptop wherre this macro looks like it will
> work fine.  The formula used is as follows:
[quoted text clipped - 20 lines]
>
> Any ideas?
Tom Ogilvy - 24 Jan 2006 02:11 GMT
Also worked unchanged in

Windows 98 SE
Excel 97

Signature

Regards,
Tom Ogilvy

> Best I can tell you is that this worked fine for me:
>
[quoted text clipped - 42 lines]
> http://www.excelforum.com/member.php?action=getinfo&userid=23758
> > View this thread: http://www.excelforum.com/showthread.php?threadid=504003
chalky - 24 Jan 2006 10:39 GMT
This code seems to be running the macro now but no sound is coming out!
I have checked the volume and that is fine - i am at a lose!

Signature

chalky

Tom Ogilvy - 24 Jan 2006 19:04 GMT
Do you get sounds otherwise?   If not, perhaps you have mute turned on.

Signature

Regards,
Tom Ogilvy

> This code seems to be running the macro now but no sound is coming out!
> I have checked the volume and that is fine - i am at a lose!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.