ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   WAV files (https://www.excelbanter.com/excel-programming/405524-wav-files.html)

David Overington[_2_]

WAV files
 
Is it possible to call up WAV files in Excel XP? I seem to recall this was
easy in earlier versions but I can't find anything in VB help files.
Thanks.
David



Leith Ross[_2_]

WAV files
 
On Feb 3, 9:15 pm, "David Overington" wrote:
Is it possible to call up WAV files in Excel XP? I seem to recall this was
easy in earlier versions but I can't find anything in VB help files.
Thanks.
David


Hello David,

You need to call an API to play a sound file. Here is the code. Change
the file path to the sound file you want to play in the macro
"PlaySoundFile". Load this into a Standard VBA module.

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

Sub PlaySoundFile()

Dim Ret As Long
Const SND_SYNC As Long = &H0 'play synchronously (default)

Ret = PlaySound("C:\MyWavFile.wav", 0&, SND_SYNC)

End Sub

================================================== ====================================
End Macro

Sincerely,
Leith Ross

David Overington[_2_]

WAV files
 
Perfect!
Many thanks, Leith, for the code and the clear layout.
Regards,
David

"Leith Ross" wrote in message
...
On Feb 3, 9:15 pm, "David Overington" wrote:
Is it possible to call up WAV files in Excel XP? I seem to recall this
was
easy in earlier versions but I can't find anything in VB help files.
Thanks.
David


Hello David,

You need to call an API to play a sound file. Here is the code. Change
the file path to the sound file you want to play in the macro
"PlaySoundFile". Load this into a Standard VBA module.

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

Sub PlaySoundFile()

Dim Ret As Long
Const SND_SYNC As Long = &H0 'play synchronously (default)

Ret = PlaySound("C:\MyWavFile.wav", 0&, SND_SYNC)

End Sub

================================================== ====================================
End Macro

Sincerely,
Leith Ross





All times are GMT +1. The time now is 09:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com