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?
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
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.
 

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
Or, does anyone else know a way to reliably play background music on a form?
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,211
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!
 

Steve_

Board Regular
Joined
Apr 28, 2010
Messages
167
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,102,764
Messages
5,488,708
Members
407,654
Latest member
IDAL

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top