Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

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

JerryDal (Programmer)
3 Jul 11 16:24
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
 
JerryDal (Programmer)
13 Jul 11 11:07
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
 
sarduspater (Programmer)
15 Jul 11 9:18
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.

JerryDal (Programmer)
15 Jul 11 13:33
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
 

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