PDA

View Full Version : Playing Midi Files in VBA



rajkumar
09-18-2008, 05:03 PM
Hi Experts,

How to play midi files from vba? i tried one from j-walk web site but received an error

file:///C:/DOCUME%7E1/ycvf878f/LOCALS%7E1/Temp/moz-screenshot.jpg"The specified device is not open or not recognized by MCI"

the code i used is



Private Declare Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long

Sub PlayMIDI()
MIDIFile = "Mission_Impossible.mid"
MIDIFile = "D:\Profiles\YCVF878F\My Documents\My Music\Midi" & "\" & MIDIFile
mciExecute ("play " & MIDIFile)
End Sub

Sub StopMIDI()
MIDIFile = "Mission_Impossible.mid"
MIDIFile = "D:\Profiles\YCVF878F\My Documents\My Music\Midi" & "\" & MIDIFile
mciExecute ("stop " & MIDIFile)
End Sub


Any help is greatful

Raj

Kenneth Hobs
09-18-2008, 05:39 PM
You may have no program associated with MID files. Or, the filename may not exist.
[VCode]

Private Declare Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long

Sub Midi(action As String, midiFilename)
If Dir(midiFilename) = "" Then
MsgBox midiFilename & vbCrLf & "Does Not Exist."
Exit Sub
End If
mciExecute action & " " & midiFilename
End Sub

Sub PlayMIDI()
Dim mf As String
mf = "D:\Profiles\YCVF878F\My Documents\My Music\Midi" & "" & "Mission_Impossible.mid"
mf = "c:\i386\pinball.mid"
Midi "play", mf
End Sub

Sub StopMIDI()
Dim mf As String
mf = "D:\Profiles\YCVF878F\My Documents\My Music\Midi" & "" & "Mission_Impossible.mid"
mf = "c:\i386\pinball.mid"
Midi "stop", mf
End Sub[/Code]