PDA

View Full Version : System beep



Djblois
07-13-2006, 09:28 AM
After my code is done I want it to run a system beep. How can I do this?

OBP
07-13-2006, 09:40 AM
The VBA comand for making the beep sound is

Beep

It will sound just one beep so if you want more you need to repeat the line of code or put it in a loop.

Djblois
07-13-2006, 09:55 AM
I put beep in but it doesn't make a sound? And I don't have it on mute and I can hear other sounds.

Daniel

OBP
07-13-2006, 10:09 AM
Daniel, it works for me, although it is very difficult to get it to beep more than once.
You may need to turn the sound up higher to hear it.

Djblois
07-13-2006, 10:32 AM
lol I have the sound up all the way right now. lol

Djblois
07-13-2006, 12:09 PM
I just tried this code on another computer and it didn't work either? have any idea why?

Cyberdude
07-13-2006, 01:28 PM
I tried to get Beep to work on 3 different computers, and I never heard anything. What I really need is a sound that goes "phffft!".

Cyberdude
07-13-2006, 01:30 PM
I just thought of something. Maybe you can get the speech facility to help you. Look into it ... it's really kinda cool.

Djblois
07-13-2006, 01:40 PM
Since, the system beep won't work can someone help me to get it to make any sound? I just want it to make a noise when it is done.

lucas
07-13-2006, 01:42 PM
How about using a .wav file?

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

I think this is a kb entry from some time ago.

Cyberdude
07-13-2006, 02:55 PM
Or you can put the following statement at the end of your code:
Application.Speech.Speak("Beep")

mdmackillop
07-13-2006, 03:07 PM
For sound see here
http://www.vbaexpress.com/forum/showthread.php?t=8736

Hi Steve,
DRJ did the Sound KB

OBP
07-13-2006, 03:13 PM
I have just had a thought, the guys that can't get the sound to work, what References have you got ticked in the reference library?

Cyberdude
07-14-2006, 01:36 PM
What reference should I have that I might not have??

P.S. I can use the text to speech feature OK.

OBP
07-14-2006, 01:48 PM
I have the following ticked
Visual Basic For Applications - (Which I assume you must have)
Microsoft Excel 10.0 Object Library
OLE Automation
Microsoft Office 10.0 Object Library

Hotpepper
07-16-2006, 02:10 PM
Also for Beep, you need to make sure that you have a sound assigned for Default Beep in the Sounds & Multimedia (this is what it's called in Windows 2000, not sure about XP) Control Panel.

malik641
07-16-2006, 06:45 PM
Daniel, it works for me, although it is very difficult to get it to beep more than once.
Sub test()
Beep
Application.Wait Now + TimeValue("00:00:01")
Beep
End Sub
And the sound works for me...:dunno

Windows XP
Excel 2003

compariniaa
07-17-2006, 03:00 PM
I put beep in but it doesn't make a sound? And I don't have it on mute and I can hear other sounds.

Daniel I think system admins can turn sounds off for computers, which may affect whether or not you can hear the beep. I can hear sounds on my PC, evidenced by this macro:

sub Sound()
If Application.CanPlaySounds = False Then
MsgBox "Your computer cannot play sounds"
Else
MsgBox "Your computer can play sounds"
End If hope this helps

Cyberdude
07-17-2006, 03:30 PM
Yes, that is not to be forgotten. I recently was trying to use an API to play a WAV sound, and it kept failing. I added:
Application.EnableSound = True
and ...Voila!.. it worked!