Playing MP3 Files From Excel
If you create a hyperlink in a cell that points to an MP3 file, clicking the hyperlink plays the audio file in your default MP3 program. But there's a big problem: You will get at least one (probably two) annoying security messages. Microsoft has described a way to disable these messages, but it's a complicated procedure.
Here's an alternative approach that uses a simple VBA macro. The macro assumes the active cell contains a compete filepec for an MP3 file (that is, the full path and the filename).
Sub PlayMP3() Application.ScreenUpdating = False On Error Resume Next ActiveSheet.OLEObjects.Add(Filename:=ActiveCell.Text, Link:=True).Select If Err.Number <> 0 Then Application.ScreenUpdating = True MsgBox "Could not play " & ActiveCell.Text Exit Sub End If Selection.Verb Selection.Delete End Sub
The PlayMP3 procedure creates an OLE object that links to the file in the active cell. The Verb method loads the linked file into the default MP3 player, and then the OLE object is deleted. If the active cell contains something other than a valid path to an MP3 file, a message is displayed and nothing happens. It's fast, and you'll never see a security warning message.
By the way, this VBA macro also works with image files. If the active cell contains a path to an image file, the file is displayed in your default image viewing software.
Search for Tips
Browse Tips by Category
Needs tips? Here are two books, with nothing but tips:
Contains more than 200 useful tips and tricks for Excel 2007 | Other Excel 2007 books | Amazon link: John Walkenbach's Favorite Excel 2007 Tips & Tricks