Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

media player on worksheet

Status
Not open for further replies.

striveforexcelence

Technical User
Oct 5, 2005
34
US
hello all

I recently did a project where I needed Windows Media Player to play a video using vba. This opened an isntance of media player. Then I was contacted by someone who saw my posts and he would like to use media player directly on a worksheet. I have placed a media player on a worksheet but I have played with it and don't know how to assign a video to the player. Does anyone know how to do this? Thank you for any direction.
 
right click hyperlink point to folder for film ?

does that help


"Research is what I'm doing when I don't know what I'm doing."
 
Hello,

Here's a possible solution, but maybe not the best practice.

In the Visual Basic Editor, I set a reference to the Windows Media Player Library. I embedded the Windows Media Player in Sheet 1, and found that is was associated with the formula =EMBED("WMPlayer.OCX.7",""). In the following code, I used the "WMPlayer" business to get a reference to the Media Player, and played a file using the URL method.

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

Best Regards,
Walter
 
I'm sorry I used the code above but I still dont seem to have any association between the player and the code. Am missing something? The player has the buttons greyed out so I am sure there is no association.

(You cannot hyperlink)
 

You can play something from the code using

oWmp.URL = "C:\Windows\Media\chimes.wav"

but replace my "chimes" path with the appropriate path or URL for what you want to play.

Now trying to figure out how to activate the buttons for manual play. As a workaround, you could put your own buttons on the sheet, but it would be cleaner if the usual Media player controls worked...
 
Maybe this is useful. If you manually embed the Media Player in a worksheet, then

1. Get into design mode.
2. Select the embedded Media Player.
3. Display its Properties.
4. One of the properties is named something like "Property Page". Click on the "..." next to this property. A form opens with the Media Player Properties.
5. Toward the left and bottom is a frame of "Replay options". One of them is something like "Automatically Start". Make sure that this one is not checked.

If you do this, then the Window Media Player controls will be click-able. Furthermore, you can put the path or URL of what you want to play in the "Source" text-box.

Sorry that I'm vague about the labels in these forms. My home PC is running a foreign language system.

Would it be useful to have a program that does these things, or is it enough to be set them up manually?

Best Regards,
Walter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top