Hi and welcome to MrExcel!
There are a couple of ways of doing this. The first method can be used to play a "wav" file. The second method can be used to play "wma", "mp3" and other file types able to played using the windows media player.
First method
In your VBA code, add the following declaration at the top of your module:
Code:
Private Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Then to play a "wav" file, call it using this line of code:
Code:
sndPlaySound "C:\WINDOWS\Media\tada.wav", 0
Change the "C:\WINDOWS\Media\tada.wav" part to the actual path and file name of the "wav" file you want to play.
Second method
With this method you need to embed a Windows Media Player control into a form. Open the form in design view, open the toolbox and select the "more controls" option - scroll down to "Windows Media Player" and add a media player control to your form, it may be given a name like WindowsMediaPlayer1. Open the VBA editor, and add the following code to your existing module:
Code:
'variable declaration
Dim tmpStr As String
'....
'your existing code
'....
'add this to the end of your routine
tmpStr = "E:\MyMusic\MySong.mp3"
Me.WindowsMediaPlayer1.URL = tmpStr
Change the "E:\MyMusic\MySong.mp3" to the actual path and file name of the song you want to play.
HTH, Andrew
P.S. The windows media player control does not need to be visible on the form to play the song, but it will need to be visible to be able to stop playing the song.