Launch a music from a access macro

pubfornhe

New Member
Joined
Aug 2, 2007
Messages
2
Hello,

I have written a macro that must do a very long task.
I would like to be informed that the task is finished by playing a music at the end of the macro (the beep is not enough).

Is there a way to launch a music file stored on my computer from the macro ?

Thanks,

Pubfornhe
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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.
 
Upvote 0
Thanks

Thanks for your quick reply.
I had found the first option somewhere on internet, but thanks to you, I really understood how it works.
Both are working.
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

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