Dim player as object ( windows media player )

Stridhan

Well-known Member
Joined
Mar 5, 2014
Messages
568
Hi

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? :eeek:
Im on excel 2010.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Thank you mole999

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

Regards,

CJ
 
Last edited:
Upvote 0
Thanks for sharing MrIfOnly.

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?
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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