Adding WindowsMediaPlayer to a form...At runtime.

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
Just like the Title says..

I am trying to figure out how to add a WindowsMediaPlayer control to a form via code. I am not able to find the correct syntax for it. Apparently, it is not done the same way as adding MSForms controls such as labels, texboxes, commandbuttons, etc..

Has anyone seen this done before?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
It does not include syntax for programmatically adding the control. Only manipulating one that is already on a form. Sadly, my project does not contain forms or controls. this is all created on the fly at runtime and destroyed afterwards.
 
Upvote 0
First, set a reference to Windows Media Player (Visual Basic Editor >> Tools >> Reference). Then try something like this...

Code:
Private Sub UserForm_Initialize()

    Dim objPlayer As WMPLib.WindowsMediaPlayer
    
    Set objPlayer = Me.Controls.Add("WMPlayer.OCX.7")
        
    With objPlayer
        .Left = 10
        .Top = 10
        .Url = "http://stream-dc1.radioparadise.com/aac-320"
    End With
    
End Sub

Hope this helps!
 
Upvote 0
First, set a reference to Windows Media Player (Visual Basic Editor >> Tools >> Reference). Then try something like this...

Code:
Private Sub UserForm_Initialize()

    Dim objPlayer As WMPLib.WindowsMediaPlayer
    
    Set objPlayer = Me.Controls.Add("WMPlayer.OCX.7")
        
    With objPlayer
        .Left = 10
        .Top = 10
        .Url = "http://stream-dc1.radioparadise.com/aac-320"
    End With
    
End Sub

Hope this helps!


OMG! This got away from me! I did not see your reply. This works perfectly and was easily adapted to my runtime-built forms. Thanks!
 
Upvote 0
You're very welcome, and thanks for the feedback.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,223,674
Messages
6,173,746
Members
452,533
Latest member
Alex19k

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top