Errors Closing Userform

Z

ZipCurs

Hello,

I have been working for some time to automate opening a video or audio file
& limiting play to the period between a start and finish time. I have
decided to focus on a wmp.dll based object placed on a UserForm and use code
on the UserForm to limit and control the play. I am working in Excel 2007 on
a Windows XP systems. The code is below:

Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long)
Dim MyStart As Long
Dim MyEnd As Long
Dim MyFile As String

MyFile = Range("B2")
MyStart = Range("B3")
MyEnd = Range("B4")

DoEvents

UserForm1.Enabled = True

Recheck:

If WindowsMediaPlayer1.playState = wmppsStopped Then
WindowsMediaPlayer1.Controls.currentPosition = MyStart
DoEvents
ElseIf WindowsMediaPlayer1.playState = wmppsPaused Then
DoEvents
ElseIf WindowsMediaPlayer1.playState = wmppsPlaying Then
Do
If WindowsMediaPlayer1.playState <> wmppsPlaying Then GoTo Recheck
DoEvents
Loop Until WindowsMediaPlayer1.Controls.currentPosition > MyEnd

WindowsMediaPlayer1.Controls.Stop
End If

DoEvents

End Sub

The code works fine, except when the UserForm is closed with the "X" in the
upper right hand corner of the UserForm. I get the following error if the
media is actively playing and the developer window is still locked:

Run-time error '-2147417848 (80010108)':
Automation error
The object invoked has disconnected from its clients.

If it is not obvious, the macro is in a Do loop at that time. I am ok with
not being able to close the UserForm if the media is running, but I do need
to have user access to the WMP UI enabled. (i.e. Userform1.Enabled=False
will not work)

Any thoughts about how to resolve this error would be greatly appreciated.
Thank you in advance.

ZipCurs
 

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