play wav file while macro runs

danno_mbk

Board Regular
Joined
Sep 6, 2004
Messages
102
is it possible to play a wav file while a macro runs ?

sort of like holding music ?

thanks
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
http://www.exceltip.com/st/Playing_WAV-files_using_VBA_in_Microsoft_Excel/460.html


It's easy to play soundfiles in WAV-format. You only need to know the filename of the sound you want to play,
and decide if you want the macro to wait while the sound plays or not. Here is an example:

Code:
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
 
Upvote 0

Forum statistics

Threads
1,203,453
Messages
6,055,528
Members
444,794
Latest member
HSAL

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top