Ciao Vladimiro,
da quello che leggo in sndPlaySound Function
<The sndPlaySound function plays a waveform sound specified either by a file name or by an entry in the registry or the WIN.INI file. This function offers a subset of the functionality of the PlaySound function; sndPlaySound is being maintained for backward compatibility.>
Credo (ma non ho provato) che anche per la sua sostituta PlaySound ci sia lo stesso problema, ovvero può utilizzare solo file Wav.
Cercando nel web ho trovato però questa discussione "Play any audio file using vba excel" in cui è riportato del codice che ho
utilizzato con successo per suonare un file mp3. Di seguito una versione leggermente modificata:
Private Declare PtrSafe Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal lpstrCommand As String, ByVal _
lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _
hwndCallback As Long) As Long
Private sMusicFile As String
Private Play
Public Sub PlaySound()
sMusicFile = "TuoFile.mp3"
Play = mciSendString("play " & sMusicFile, 0&, 0, 0)
If Play <> 0 Then 'this triggers if can't play the file
'Play = mciSendString("'play " & sMusicFile & "'", 0&, 0, 0) 'i tried this aproach, but doesn't seem to work
End If
End Sub
Public Sub StopSound()
sMusicFile = "TuoFile.mp3"
Play = mciSendString("close " & sMusicFile, 0&, 0, 0)
End Sub
Qualcosa di molto simile è riportata anche da John Walkenbach nelle sue pagina "Playing Sound From Excel" a proposito di file MIDI.
Private Declare Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long
Sub PlayMIDI()
MIDIFile = "xfiles.mid"
MIDIFile = ThisWorkbook.Path & "\" & MIDIFile
mciExecute ("play " & MIDIFile)
End Sub
Sub StopMIDI()
MIDIFile = "xfiles.mid"
MIDIFile = ThisWorkbook.Path & "\" & MIDIFile
mciExecute ("stop " & MIDIFile)
End Sub---
Cambiando il file il medesimo codice funziona perfettamente anche per MP3
David