Playing WAV Files

Frank asks:

Dick, would it be a lot of trouble to make the American National Anthem play when displaying the flag?

First, go to the Embassy of the United States of America in Stockholm, Sweden’s website and download their wav file of the national anthem.

Next, go to The Spreadsheet Page and borrow John’s code for playing a wav file.

With a little modification, the code looks like this:

Private Declare Function PlaySound Lib “winmm.dll” _
  Alias “PlaySoundA” (ByVal lpszName As String, _
  ByVal hModule As Long, ByVal dwFlags As Long) As Long
 
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
 
Sub PlayWAV(ByVal sWav As String)
    Call PlaySound(sWav, 0&, SND_ASYNC Or SND_FILENAME)
End Sub

and add this to the fly the flag code

    sWav = ThisWorkbook.Path & “anthem.wav”
    PlayWAV sWav

Don’t forget to declare sWav in your code. Or you can just download the file

Download FlyFlag.zip

Posted in Uncategorized

One thought on “Playing WAV Files

  1. Dick, this is fantastic, I really owe you one on this.

    Made an Excel file with 3 sheets and commands which I’ll send to my friends and family in the States on the 4rth of July.


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.