0 votes
in VBA by Beginner (2 points)
I have a path and filename of several audio (.mp3) files in a column of an excel sheet. I'd like to be able to play the chosen mp3 file without opening an additional mediplayer and be able to stop the music file on the click of a button. Has anybody come across a solution? I could share a code for wmv files if this is of any interest. Regards LuBu
by Expert (892 points)
Hello

As far as I know, if you need to play mp3, excel will open the mediaplayer replated to your system. But wmv doesn't require additional mediaplayer.

1 Answer

0 votes
by Expert (892 points)

This is the code that may help you (but the mediaplayer will be used)

Private 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
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWNORMAL As Long = 1

Sub PlayMusic(strFile As String)
    If ShellExecute(0&, "Play", strFile, 0&, 0&, SW_SHOWNORMAL) < 33 Then
        MsgBox "Something Went Wrong", vbInformation
    End If
End Sub

Sub Test()
    Call PlayMusic(ThisWorkbook.Path & "\052.mp3")
End Sub

 

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.

Register

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...