PDA

View Full Version : Windows media player on excel spreadsheet



thekneeguy
10-23-2005, 04:34 PM
Hello,

I have a worksheet with a media player on it. I would like to be able to play a video without opening a separate instance of WMP. Someone suggested the following code which i tried to alter to my specifics but I am getting no association between the code and the player. The buttons for play, etc. are still all greyed out. does anyone have any idea what I am missing? thank you

Option Explicit
Sub TryPlayer()

Dim oSh As Worksheet
Dim oWmp As WindowsMediaPlayer

Dim o As Object
Dim v As Variant

'*****************************************
'Get a reference to the Media Player.
'Awkward, but couldn't find a better way.
'*****************************************
Set oSh = Worksheets("Sheet1")
oSh.Activate
oSh.Cells(1, 1).Activate

For Each v In oSh.OLEObjects
If v.progID Like "WMPlayer*" Then
Set oWmp =
v.Object
Exit For
End If
Next v

If IsNull(oWmp) Then
MsgBox "Couldn't find WindowsMediaPlayer"
Exit Sub
End If


'*****************************************
'Play chimes.
'*****************************************
oWmp.URL = "C:\WINNT\Media\chimes.wav"
End Sub

Ivan F Moala
10-23-2005, 11:33 PM
This worked for for
The Embeded media player is Private to the container it is in = the Activesheet
Hence my code references the Sheet Code name = Sheet1
Try substituing for this.



Dim WMP As WindowsMediaPlayer

Set WMP = Sheet1.WindowsMediaPlayer1
WMP.URL = "C:\WINDOWS\Media\chimes.wav"