» Playing MIDI-files using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - General Topics in VBA
VERSION - All Microsoft Excel Versions
Soundfiles in MIDI-format are often long, so it might be necessary to stop playingthe 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
Else
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
Book Store:
Recommended Books:
- Microsoft Excel 2002 Visual Basic for Applications Step by Step
- Analyzing Markets, Products, and Marketing Plans
- The Analysis and Use of Financial Statements
- Adventure Capitalist: The Ultimate Road Trip
- A Mathematician Plays the Stock Market
- Essentials of Investments with Standard & Poor's Educational Version of Market Insight + PowerWeb + Stock Trak Coupon
No comments have been submitted.

