Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Play MIDI and MP3 Files From Excel VBA On Windows XP PC

Status
Not open for further replies.

JerryDal

Programmer
Jul 2, 2011
5
US
I am working on a personal Excel program the plays MP3 and MIDI files stored on disk. The VBA code to play audio files works flawlessly on my Windows 7 laptop, however when I run the same code on a Windows XP PC, there are no error messages, and no sound. Maybe someone out there knows that different code is needed in the XP environment and what it should be.
Jerry

Here is the code from an Excel 2003 workbook created for test purposes:

Private Declare 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

Dim sMusicFile As String

Dim Play

Private Sub cmdPlayMusic_Click()

sMusicFile = Me.txtFileName.Text ‘path has been included. Ex. “C:\3rdMan.mp3”

Play = mciSendString("play " & sMusicFile, 0&, 0, 0)

If Play <> 0 Then MsgBox "Can't PLAY!"

Me.cmdPlayMusic.Enabled = False
Me.cmdStopMusic.Enabled = True

End Sub

Private Sub cmdStopMusic_Click()

Play = mciSendString("close " & sMusicFile, 0&, 0, 0)

cmdPlayMusic.Enabled = True
cmdStopMusic.Enabled = False

End Sub
 
My solution to playing MP3 and MIDI files from an Excel workbook, which will run in both Windows 7 and XP, is to use a WindowsMediaPlayer control on the worksheet. From References in the VB editor, I added "Windows Media Player" from the list of references.

Code to start and stop the player:
Function Play_Music(Path_FileID As String)

Sheets(1).cmdStopMusic.Enabled = True
Sheets(1).WindowsMediaPlayer1.Visible = True
Sheets(1).WindowsMediaPlayer1.URL = Path_FileID

End Function

Function Stop_Playing()

Sheets(1).cmdStopMusic.Enabled = False
Sheets(1).WindowsMediaPlayer1.Visible = False
Sheets(1).WindowsMediaPlayer1.Close

End Function

RESOLVED
 
Your pgm on my work's pc sounds very well.

I think the problem is not Xp.

Candu si tene su 'entu es prezisu bentolare.
 
Thank you starduspater for taking the time to test the original code to play both MIDI and MP3 files on an XP PC, and letting me know that it worked.

After running the Excel 2003/VBA application, which uses mciSendString to play MIDI and MP3, and finding that MP3 files played on my Windows 7 PC but were silent on the XP machine, I chose to use an invisible WindowsMediaPlayer control on the worksheet, and it runs well on both systems.

Jerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top