PDA

View Full Version : [SOLVED] Beep in Excel



IrishCharm
06-09-2008, 08:37 AM
Hi,

I am trying to create a macro whereby there is a beep whenever a certain function is hit/run, i.e. when a variable is hit then a beep of some sort sounds.

Any ideas on how this may be achieved?

Thanks

Sarah

:cloud9:

Bob Phillips
06-09-2008, 08:39 AM
Why?

IrishCharm
06-09-2008, 08:45 AM
It's actually for a friend of mine who is a primary teacher - she is teaching the kid's how to use excel, i.e. how to open and do basic math (eg 5x4) on it and was asking me if there was a way that it could be used to try and make using math and excel a bit more fun.... attantion span of kid's is not the longest!!!!

IrishCharm
06-09-2008, 08:51 AM
Hi,

I have found a bit of code in Google that will work for me... might keep the school kids interested for a little while!!

thanks for your help

Sarah

IrishCharm
06-09-2008, 08:58 AM
Hi,

I have attached the code if anyone is interested in the above function - it sends out several different types of beeps.



Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, _
ByVal dwDuration As Long) As Long
Sub TestBeep()
Beep 500, 100
Application.Wait (Now + TimeSerial(0, 0, 1))
Beep 1000, 100
Application.Wait (Now + TimeSerial(0, 0, 1))
Beep 5000, 100
Application.Wait (Now + TimeSerial(0, 0, 1))
Beep 2000, 100
Application.Wait (Now + TimeSerial(0, 0, 1))
Beep 200, 100
End Sub

RonMcK
06-09-2008, 09:26 AM
Sarah,

Thanks for sharing your findings.

Did you try using Beep by itself? I see it and some examples mentioned in Help.

And for the Lurkers, Sarah's code works for Windows but not Mac.

Cheers!

mdmackillop
06-09-2008, 01:01 PM
A bit more complex, but gives the possibility of different beeps in this thread (http://www.vbaexpress.com/forum/showthread.php?t=19060)

lucas
06-09-2008, 02:02 PM
If you want to play a .wav file you might try this. Save your excel file and put the wave file in the same directory. Change the name of the wave file in the code to match what you want to play. Name in the code is LoadIt.WAV:


Option Explicit
'API Class to take care of playing the file
Public Declare Function sndPlaySound32 Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Sub VBASound()
'Call Api to play LoadIt.wav witch is in the same folder as
'the active document!
Call sndPlaySound32(ActiveWorkbook.Path & "\LoadIt.WAV", 0)
End Sub

IrishCharm
06-10-2008, 06:08 AM
Anyone who can set my beep up to play Chopsticks I'll help them finish a keg of Guinnes next time they're in Dublin :-)

Thanks for all the help

Sarah