» Playing WAV-files using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - General Topics in VBA
VERSION - All Microsoft Excel Versions
and decide if you want the macro to wait while the sound plays or not. Here is an example:
Public Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
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
Sub TestPlayWavFile()
PlayWavFile "c:\foldername\soundfilename.wav", False
MsgBox "This is visible while the sound is playing..."
PlayWavFile "c:\foldername\soundfilename.wav", True
MsgBox "This is visible after the sound is finished playing..."
End Sub
Book Store:
Recommended Books:
- Word 2002: The Complete Reference
- The Interpretation of Financial Statements
- The McGraw-Hill Guide to Writing a High-Impact Business Plan: A Proven Blueprint for First-Time Entrepreneurs
- The Financial Numbers Game: Detecting Creative Accounting Practices
- Final Accounting: Ambition, Greed and the Fall of Arthur Andersen
- The Essential 55: An Award-Winning Educator's Rules for Discovering the Successful Student in Every Child
WdW
If I scroll then the sound doesn't play anymore. Is there something to do about that?

