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! :)
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

agiammo

Board Regular
Joined
May 9, 2002
Messages
68
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.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092

ADVERTISEMENT

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
 

MartinK

Active Member
Joined
Oct 30, 2003
Messages
384
depending on your settings, you may also want to omit the .wav extension.
 

agiammo

Board Regular
Joined
May 9, 2002
Messages
68

ADVERTISEMENT

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)
 

agiammo

Board Regular
Joined
May 9, 2002
Messages
68
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
 

agiammo

Board Regular
Joined
May 9, 2002
Messages
68
I added the code

Sub Test()

like Andrew suggested and I still get the same error message. :confused:
 

Watch MrExcel Video

Forum statistics

Threads
1,123,304
Messages
5,600,864
Members
414,409
Latest member
FloordAlex

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
Top