Consulting

Results 1 to 2 of 2

Thread: Playing Midi Files in VBA

  1. #1

    Playing Midi Files in VBA

    Hi Experts,

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

    [IMG]file:///C:/DOCUME%7E1/ycvf878f/LOCALS%7E1/Temp/moz-screenshot.jpg[/IMG]"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
    Last edited by Aussiebear; 03-26-2023 at 01:27 AM. Reason: Adjusted code tags

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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]
    Last edited by Aussiebear; 03-26-2023 at 01:28 AM. Reason: Adjusted code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •