Macro to run Windows Media Player

GoodmanJim

Board Regular
Joined
Aug 24, 2003
Messages
95
I have a series of reports in mp3. I would like to create a screen of buttons to play the reports.

I can make the buttons, but have no idea on how to write a macro to run Windows Media Player from the buttons.

Can someone help me?

Thank you in avdance
Jim Goodman
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Thanks Gary, but I make it to simple in my explanation. I have one button of one page to "Play report". The Excel page changes contain based on what the person in looking for and button will remain the same for all pages. Therefore I run a macro to find the report with a extract of that report and on that common page is a button to "Play Report". The button is on that common page.

Thanks
Jim
 
Upvote 0
Jim,

In general, if you want to launch a program from within VBA, you can use the SHELL command. It can launch Windows Media Player and automatically play whatever file you tell it to within the VBA macro.

Code:
Private Sub CommandButton1_Click()
    FileToPlay = """C:\Documents and Settings\RuRichter\Desktop\rainreport.mp3"""
    Shell "C:\Program Files\Windows Media Player\wmplayer /play /close " & FileToPlay
End Sub

Your path and/or filename will likely have spaces in it, so put triple double quotes around the path/filename. It will look like this:

There are 3 quotes at the end--two for the path/filename and one to enclose the Shell argument.

Here are some other switches you may need to use for your Shell command:
/open: Open the file, don't automatically start playing.
/play: Start playing the file as soon the player is launched.
/close: Close the player after playback (only works when used with /play).
/fullscreen: Start the file in full-screen mode.
/new: Use a new instance of the player.

HTH
Russ
 
Upvote 0
Jim,

In general, if you want to launch a program from within VBA, you can use the SHELL command. It can launch Windows Media Player and automatically play whatever file you tell it to within the VBA macro.

Code:
Private Sub CommandButton1_Click()
    FileToPlay = """C:\Documents and Settings\RuRichter\Desktop\rainreport.mp3"""
    Shell "C:\Program Files\Windows Media Player\wmplayer /play /close " & FileToPlay
End Sub

Your path and/or filename will likely have spaces in it, so put triple double quotes around the path/filename. It will look like this:

There are 3 quotes at the end--two for the path/filename and one to enclose the Shell argument.

Here are some other switches you may need to use for your Shell command:
/open: Open the file, don't automatically start playing.
/play: Start playing the file as soon the player is launched.
/close: Close the player after playback (only works when used with /play).
/fullscreen: Start the file in full-screen mode.
/new: Use a new instance of the player.

HTH
Russ

is it possible for this method to open the player at a certain time of the song?
and if not, do you know any way to do this?
 
Upvote 0

Forum statistics

Threads
1,223,639
Messages
6,173,499
Members
452,517
Latest member
SoerenB

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