Is there a way to declare the windows media player as an object or variant only by the default references?
Its not in a form.
If yes, how?
Im on excel 2010.
Found below which would work if only the player closed afterwards, any idea why it wont work for me?
Code:
Sub test()
FileToPlay = """C:\Users\Public\Music\Sample Music\Kalimba.mp3"""
Shell "C:\Program Files\Windows Media Player\wmplayer /play /close " & FileToPlay
End Sub
If you insert the media player as an activeX control on worksheet 1 then try this:
Code:
Sub test()
With Worksheets(1).OLEObjects("WindowsMediaPlayer1").Object
If .playState <> 3 Then
.Enabled = True
.Url = "C:\Users\Public\Music\Sample Music\Kalimba.mp3"
.Settings.volume = 100
.Controls.Play
Else: .Controls.stop
End If
End With
End Sub
You can find more settings for the media player in the Object Browser.
Also, you can setup another sub in your worksheet module to catch errors with the player. For example:
Code:
Private Sub WindowsMediaPlayer1_MediaError(ByVal pMediaObject As Object)
MsgBox "The media file was not found"
End Sub
Main goal is to not use a form or insert it in a sheet.
Using Shell work almost fine for me but from what Ive read in other posts /Play /Close should close the player when done but it stays open?
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.