How do I run WMP as an ActiveX object from Excel-VBA

J

John Keith

What is the syntax to create/run WMP as an ActiveX Object from VBA or
VB-Script?
All of the examples I find are in javascript and I cant seem to get it to
work in VB.

on a discussion thread about Windows Media Player I found this info:
You'll need to run it as an ActiveX object in VB, for which you need
the ProgID : I think it could be WMPlayer.OCX.7 : It'll be in your
registry, search for a value of 6bf52a52-394a-11d3-b153-00c04f79faa6
and look at the ProgID

I did look in my resistry and WMPlayer.OCX.7 is the correct ProgId, but how
do you bind that so that I can explore the object model using the VB
debugging tool inside excel (since this is the only one I am familiar with).
I have found the info on how to request access rights to be able to update
the WMP objects. But they ALL assume you have already bound the model.
There was also an IMPORTS statement that looks like its purpose is to tell
VBA about the WMP object model. But I think that is a .net only statement
(I'm running Excel2002) and I cant find any info on how it was done before
..net.

Link to the object model I'm trying to use:
http://msdn.microsoft.com/library/d...diacollectiongetattributestringcollection.asp
 
T

Tom Ogilvy

In the VBE,
go into tools=>References and look for Windows Media Player down toward the
bottom. click in the checkbox and close the dialog.
Now you should be able to look at it in the object browser
 
M

michelxld

Hello john ,Hello Tom

I hope these examples help you


Play And Stop
***********

Option Explicit
Dim Wmp As WindowsMediaPlayer
'activate Windows Media Player reference

Sub jouerMediaPlayer()
Set Wmp = CreateObject("WMPlayer.OCX.7")
Wmp.URL = "C:\Documents and Settings\michel\dossier\myMusic.mid"
Wmp.Controls.Play
End Sub

Sub arreterMediaPlayer()
If Wmp Is Nothing Then Exit Sub
Wmp.Controls.stop
End Sub



Duration of musical sequence
***********************

Dim ValMin As Double, ValSec As Double, S As Double
Set Wmp = CreateObject("WMPlayer.OCX.7")

Wmp.URL = "C:\monFichier.mp3"
While Wmp.PlayState = 9: DoEvents: Wend

S = Wmp.currentMedia.Duration
ValMin = Application.WorksheetFunction.RoundDown((S / 60), 0)
ValSec = Application.WorksheetFunction.RoundDown(S, 0) - (ValMin * 60)
MsgBox Format(ValMin, "00") & ":" & Format(ValSec, "00")



regards ,
miche
 
J

John Keith

Hi Michael and Tom...

The note about the setting References helped my hunt-and-peck method of
exploring VBA and scripting get over that hump. It would have been several
more weeks before I would have stumbled on that feature.) Thanks Tom

After browsing through the object model features for WMP (and there are a
bunch),
I was still stuck on how to do the Create.Object for WMP... Thanks for the
"live" examples Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top