PDA

View Full Version : Using Windows Media Player in VBA



Tony Jones
11-28-2007, 09:25 AM
Hi,

I am currently trying to write a VBA macro to do the following:

Open an audio or video file in Windows Media Player
Time how long it takes to do so
Close WMP once this has been doneI can do 1. However I can't seem to find a flag or value to monitor to do 2, or a command to do 3. And ideas? The code I'm currently using is:

Function AutomatedWMPPageLoading(ByVal PageToLoad As String)

Dim wmp As Object
Dim StartTime
Dim EndTime
Dim TimePageTookToLoad

Set wmp = CreateObject("WMPlayer.ocx")

' Note the time when we start to load
StartTime = Timer

' Go to a web site
wmp.openPlayer (PageToLoad)

' Loop until ie page is fully loaded
Do Until ((wmp.openState = 6) Or (Timer - StartTime > 1000))
Loop

' And the time when the load is complete
EndTime = Timer

' And how long the load took
TimePageTookToLoad = EndTime - StartTime

' And close
wmp.Close

' Clean up
Set wmp = Nothing

' And return the result
AutomatedWMPPageLoading = TimePageTookToLoad

End Function

Thanks!