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