Microsoft Office Tutorials and References
In Depth Information
Using an External Control
Figure 14-20: The Windows Media Player control.
This example was incredibly easy to create. The UserForm_Initialize procedure adds the
MP3 filenames to the ListBox. To keep things simple, it reads the files that are in the same
directory as the workbook. A more versatile approach is to let the user select a directory.
Private Sub UserForm_Initialize()
Dim FileName As String
‘ Fill listbox with MP3 files
FileName = Dir(ThisWorkbook.Path & “\*.mp3”, vbNormal)
Do While Len(FileName) > 0
ListBox1.AddItem FileName
FileName = Dir()
Loop
ListBox1.ListIndex = 0
End Sub
See Chapter 27 for more information about using the Dir command.
The PlayButton_Click event-handler code consists of a single statement, which assigns the
selected filename to the URL property of the WindowsMediaPlayer1 object.
Private Sub PlayButton_Click()
‘ URL property loads track, and starts player
WindowsMediaPlayer1.URL = _
ThisWorkbook.Path & “\” & ListBox1.List(ListBox1.ListIndex)
End Sub
You can probably think of lots of enhancements for this simple application.
 
Search JabSto ::




Custom Search