ERLANDSEN DATA CONSULTING Excel & VBA Tips   Informasjon på norsk / Information in Norwegian

These pages are no longer updated and are only available for archive purposes.

Click here to visit the pages with updated information.

Playing MIDI-files

Soundfiles in MIDI-format are often long, so it might be necessary to stop playing the sound (e.g. when the macro is finished). Here is an example:

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

Sub PlayMidiFile(MidiFileName As String, Play As Boolean)
    If Dir(MidiFileName) = "" Then Exit Sub ' no file to play
    If Play Then
        mciExecute "play " & MidiFileName ' start playing
        mciExecute "stop " & MidiFileName ' stop playing
    End If
End Sub

Sub TestPlayMidiFile()
    PlayMidiFile "c:\foldername\soundfilename.mid", True
    MsgBox "Click OK when the MIDI file starts playing..."
    MsgBox "Click OK to stop playing the MIDI file..."
    PlayMidiFile "c:\foldername\soundfilename.mid", False
End Sub


Document last updated 1999-08-13 12:50:38      Printerfriendly version


Erlandsen Data Consulting   
Excel & VBA Tips   Copyright ©1999-2024    Ole P. Erlandsen   All rights reserved
E-mail Contact Address