Button for wave file

  • Thread starter Thread starter yo beee
  • Start date Start date
Y

yo beee

Hey all,
Thanks to all programmers who help us newbies out all the time. You are
invaluable. I'm sure this issue has been here before but here goes.
I need a command button to play a wave file. My wave file is called
"chord.wav" and resides in the following directory: "C:\user\Book" My Excel
workbook resides in the same directory and is called "MNB.xls" The user hits
the button and the wave file plays. That's it.
TIA
 
Hi:

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

Sub PlayMe()
Dim retval As Long
retval = PlaySound("C:\user\Book\chord.wav", 0, &H20000)
End Sub

Regards,

Vasant.
 
Thanks Vasant,
Where does the stament go? Into the code of the command button, a
module? Please let me know and thanks for the help.
Yobeee
 
Hi Vasant,
I put the code into the button and when I clicked it, I received a
Microsoft Visual Basic error stating the following:
"Compile Error:
Constants, fixed-length strings, arrays, user-defined types and Declare
statements not allowed as Public members of object modules"

Any suggestions? Did I do something wrong?
Thanks for all the help...
Yobeee
 
Hi Yobeee:

Sorry, I should have been clearer.

In a standard module:

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

Public Sub PlayMe()
Dim retval As Long
retval = Module1.PlaySound("C:\user\Book\chord.wav", 0, &H20000)
End Sub

In the CommandButton code:

Private Sub CommandButton1_Click()
PlayMe
End Sub

Regards,

Vasant.
 
Update!
Vasant. I used the code in the module and it works fine. Play the wave
file perfectly. How do I get the command button to use the Macro?
Yobeee
 
Works Great!!! Thanks a million.
Yobeee
yo beee said:
Update!
Vasant. I used the code in the module and it works fine. Play the wave
file perfectly. How do I get the command button to use the Macro?
Yobeee


button,
 
Back
Top