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