One of the ways would be to get the length of time for the mp3 file to be played and put Excel in pause during that time to when it finishes, return the button to the default color.
To get the data from an mp3 file you can use the following macro:
Function FileInfo(path, filename, item) As Variant
Dim objShell As IShellDispatch4
Dim objFolder As Folder3
Dim objFolderItem As FolderItem2
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(path)
Set objFolderItem = objFolder.ParseName(filename)
FileInfo = objFolder.GetDetailsOf(objFolderItem, item)
Set objShell = Nothing
Set objFolder = Nothing
Set objFolderItem = Nothing
End Function
From there you can call this function by searching the data, eg:
Range("A1").value = FileInfo(currdir, filename, 20) 'Artista
Range("A2").value = FileInfo(currdir, filename, 14) 'Album
Range("A3").value = FileInfo(currdir, filename, 21) 'Título
Range("A4").value = FileInfo(currdir, filename, 26) 'Sequencia (Track#(
Range("A5").value = FileInfo(currdir, filename, 16) 'Genero
Range("A6").value = FileInfo(currdir, filename, 27) 'Duração
So I think in the middle of your macro would look something like this:
Sub aoApertarBotao()
Dim mp3Duration as String
'Altera a cor do botão para modo "tocando"
'[...] seu código para tocar a música
mp3Duration = FileInfo("C:\Caminho\do\Arquivo\mp3\", "nome da musica.mp3", 27)
Application.Wait (Now + TimeValue(mp3Duration))
'Altera a cor do botão para modo padrão
End Sub
See if you can!
Sources / Credits:
link
link