can you import an mp3 to VB in Excel '03 to be played when a form.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to save an mp3 file in my code to be played when a certain user form
opens.
The help file says that sounds have been removed from excel. Can I do this?
 
Not using anything native to Excel, at least not that I am aware of. You
would need to have a reference to an mp3 player (e.g. Windows Media Player)
in your project (and make sure you can distribute it to all users) and then
use the mp3 player's object model to load and play your file.
 
If you provide the .mp3 file and make sure it's located in the same location as
your workbook, maybe you could just let windows start up the user's MP3 player.

In the Userform module:
Option Explicit
Private Sub UserForm_Initialize()
Dim myFileName As String
myFileName = ThisWorkbook.Path & "\mymusic.mp3"
ShellExecute 0, "", myFileName, "", "", 0
End Sub

In a general module:

Option Explicit
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 

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

Back
Top