Adding WindowsMediaPlayer to a form...At runtime.
Results 1 to 8 of 8

Thread: Adding WindowsMediaPlayer to a form...At runtime.

  1. #1
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Adding WindowsMediaPlayer to a form...At runtime.

    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?

  2. #2
    Board Regular
    Join Date
    Jul 2009
    Posts
    1,672
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Adding WindowsMediaPlayer to a form...At runtime.

    Last edited by daverunt; May 17th, 2019 at 12:26 PM.

  3. #3
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Adding WindowsMediaPlayer to a form...At runtime.

    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.

  4. #4
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Adding WindowsMediaPlayer to a form...At runtime.

    Or, does anyone else know a way to reliably play background music on a form?

  5. #5
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Adding WindowsMediaPlayer to a form...At runtime.

    /bump

  6. #6
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,791
    Post Thanks / Like
    Mentioned
    32 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Adding WindowsMediaPlayer to a form...At runtime.

    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!

  7. #7
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Adding WindowsMediaPlayer to a form...At runtime.

    Quote Originally Posted by Domenic View Post
    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!

  8. #8
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,791
    Post Thanks / Like
    Mentioned
    32 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Adding WindowsMediaPlayer to a form...At runtime.

    You're very welcome, and thanks for the feedback.

    Cheers!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •