Playing WAV file

agiammo

Board Regular
Joined
May 9, 2002
Messages
68
ok, I've looked at the tip files on this subject and added some code to my VBA, but I'm still getting an error message. Help!

Here is my code:

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

WAVFile = "J:\People\Aimee\dukes_horn - dont erase.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)

MsgBox "You are done! Save now."
End Sub

I'm getting an error message that says "Compile Error: Only comments may appear after End Sub, End Function, or End Property."

Any ideas on what I have done wrong? I just want this one wav file to play when the macro is completed. The wav file is stored in a different folder out on the LAN.

Thanks! :)
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Yes, thanks. If you read my message, you will note that I have already read all the other postings to this board regarding playing WAV files. This includes reading topic 59 and topic 87. Using those tip files has gotten me this far, but I still need to figure out what is causing my error.
 
Upvote 0
You don't have a Sub procedure before your End Sub. Try something like this:

Code:
Private Declare Function PlaySound Lib "winmm.dll" _ 
Alias "PlaySoundA" (ByVal lpszName As String, _ 
ByVal hModule As Long, ByVal dwFlags As Long) As Long 

Sub Test()

Const SND_SYNC = &H0 
Const SND_ASYNC = &H1 
Const SND_FILENAME = &H20000 

WAVFile = "J:\People\Aimee\dukes_horn - dont erase.wav" 
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME) 

MsgBox "You are done! Save now." 
End Sub
 
Upvote 0
That End Sub is for the entire routine. Do I really need to set up a separate Subroutine just for that little bit of code?

What do you mean by omit the .wav extension? Do you mean have this instead:

WAVFile = "J:\People\Aimee\dukes_horn - dont erase"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
 
Upvote 0
Excel highlights this section when I get the error msg:

Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top