Excel Macro Play Sound
Excel Macro Play Sound
CanPlaySounds Then
MsgBox "Sorry, sound is not supported on your system."
Exit Sub
End If
Sub PlayWAV()
WAVFile = "dogbark.wav"
WAVFile = ThisWorkbook.Path & "\" & WAVFile
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub
In the example above, the WAV file is played asynchronously. This means execution continues while the sound is pla
Sub PlayMIDI()
MIDIFile = "xfiles.mid"
MIDIFile = ThisWorkbook.Path & "\" & MIDIFile
mciExecute ("play " & MIDIFile)
End Sub
Sub StopMIDI()
MIDIFile = "xfiles.mid"
continues while the sound is playing. If you would like code execution to stop while the sound is playing, use this statement:
broutine starts playing a MIDI file. Executing the StopMIDI subroutine will stop playing the MIDI file.
se this statement: