Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


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

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

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

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.

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

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

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
End Function


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

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.

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

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.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close