I could use Insert|object and browse to my MIDI file to insert it into a
worksheet (and hide that worksheet later).
Then I could use:
Option Explicit
Sub testme()
Dim OLEObj As OLEObject
Set OLEObj = Worksheets("sheet1").OLEObjects("object 1")
OLEObj.Verb
End Sub
But in xl2003, I was prompted with security questions to allow this potentially
harmful program to play. And then it opened up in my default MIDI player
(WinAmp for me).
I'm not sure you've seen this, but John Walkenbach can help:
http://www.j-walk.com/ss/excel/tips/tip59.htm
Stolen from his site:
Example: Playing a MIDI File
If the sound file is a MIDI file, you'll need to use a different API call. The
PlayMIDI subroutine starts playing a MIDI file. Executing the StopMIDI
subroutine will stop playing the MIDI file.
Private Declare Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long
Sub PlayMIDI()
MIDIFile = "xfiles.mid"
MIDIFile = ThisWorkbook.Path & "\" & MIDIFile
mciExecute ("play " & MIDIFile)
End Sub
Sub StopMIDI()
MIDIFile = "xfiles.mid"
MIDIFile = ThisWorkbook.Path & "\" & MIDIFile
mciExecute ("stop " & MIDIFile)
End Sub
The purpose of the check is to see if the file exists on someone elses
computer. I have a novelty program that I have written using Excel that
plays part of a midi file and if the recipient does not have the same
location, I can avoid an error message by using the If ... Then method to
first check for the path. It does not make any difference what the midi file
is, as long as there is one at that location. So what you pointed me to is
what I needed. My only other alternative would be to figure out how to
incorporate the sound into the workbook and that is over my head.