View Full Version : Beepless MsgBox
Hi all,
Is there a way to call msgbox without beeping?
There´s a particular situation in my userform in which I prefer to avoid beeping, but in all others beeping is desired.
I´m using MS Word 2003.
Thanks in advance for any help.
Rob342
06-30-2011, 07:53 AM
MK
An extract from Microsoft help file
Options.EnableSound Property
True if Word makes the computer respond with a sound whenever an error occurs. Read/write Boolean.Syntax
expression.EnableSound
expression A variable that represents a Options (http://office.microsoft.com/client/helppreview.aspx?AssetId=HV806040729990&lcid=2057&NS=WINWORD%2EDEV&Version=12&CTT=5&origin=HV080604177) object.
Example
This example sets the Provide feedback with sound option on the General tab in the Options dialog box, based on user input.
Visual Basic for Applications
If MsgBox("Do you want Word to beep on errors?", 36) = vbYes Then Options.EnableSound = TrueElse Options.EnableSound = FalseEnd If
Many thanks Rob342,
But in my case there´s no error, but just a simple message displayed by msgbox.
Anyway, I´ll keep the idea for the future.
Frosty
07-01-2011, 09:50 AM
The actual function called "msgbox" does not cause a beep by default. The application generates a beep if you click anywhere but deal with the messagebox.
Maybe you can describe your problem a bit better, since you're talking about a messagebox and a userform. Or, even better, post the code.
There are many many ways to do logic within VBA. Maybe a Select Case would be good for you, maybe just a simple If...Else...End If. .
Hi Frosty,
There´s nothing really special with my code, so I´ll post an extra-simple example of some tests I´ve made:
Private Sub CommandButton1_Click()
Options.EnableSound = False
X = MsgBox("Hello", vbYesNoCancel)
X = MsgBox("Hello", vbCritical)
X = MsgBox("Hello", vbInformation)
Options.EnableSound = true
End Sub
As you can see (hear) there are different beeps for each "button".
I´ve tried out Rob342's suggestion "Options.EnableSound=false".
I think I´ve tryed all buttons, all of them beeps.
I´ve tryed also calling msgbox with just the prompt text.
Frosty
07-01-2011, 11:18 AM
I stand corrected! That's what you get for developing for so many years without speakers.
Doesn't look like it's really a simple answer. I have two thoughts:
1. Easiest way: the time you don't want to use the messagebox with a beep, just create a userform which looks like a messagebox and works much the same way.
2. Check out the following link, as a way of turning the system volume down. However, it's pretty complicated and probably not worth the effort if you're just using a simple messagebox.
http://support.microsoft.com/kb/q178456/
I will tinker around with it, but I am getting the same results. I'd flat out forgotten that a messagebox will always beep at you... and then keep beeping if you try to click somewhere else without dealing with it.
Frosty
07-01-2011, 11:27 AM
vbQuestion as an argument will not generate a beep. Of course, you're stuck with a question mark graphic on your messagebox, which may or may not be desireable.
Sub TestMsgbox()
Dim x As Integer
x = MsgBox("Beeps")
x = MsgBox("Beeps", vbCritical)
x = MsgBox("Beeps", vbInformation)
x = MsgBox("Beeps", vbExclamation)
x = MsgBox("No Beeps", vbQuestion)
End Sub
Thanks a lot Frosty, vbQuestion does exactly what I need.
As I said, I thought I had tested them all.:doh:
Just a little explanation, why the question mark does not bothers me in this case.
I´ve written a "keypress" routine to select itens in a combobox trough "non initial letters" and for some reason the focus does not leave the control, so I placed a dummy msgbox at the end of it, as in:
If condition Then
SendKeys "{ENTER}" ' skip msgbox
v = MsgBox("", vbQuestion)
SendKeys "{TAB}" ' skip to next control
End If
There´s probaby a better solution, but it´s simple enough to justify itself.
Thanks again.
macropod
07-01-2011, 07:55 PM
See:
http://support.microsoft.com/default.aspx?scid=kb;en-us;178456
http://www.pcreview.co.uk/forums/api-commands-turn-volume-control-t1008148.html
Frosty
07-05-2011, 10:37 AM
Neat trick. Having not used SendKeys much. Seems odd to hit the enter key, then display the messagebox, and have the sent enter key "land" on the okay button of the messagebox (immediately dismissing it).
It's as if SendKeys works at the speed of sound, while the other actions work at the speed of light. Grin.
I've seen and used SendKeys "{tab}+{tab}" in the activate event to make certain the userform gets focus (which occasionally would fail to happen).
I wonder if your use of SendKeys is all you need, rather than the messagebox?
But regardless, nice to see someone else's bag of tricks.
gmaxey
07-09-2011, 12:34 PM
Here the default doesn't create a beep.
Sub TestMsgbox()
Dim x As Integer
x = MsgBox("No Beeps")
x = MsgBox("Beeps", vbCritical)
x = MsgBox("Beeps", vbInformation)
x = MsgBox("Beeps", vbExclamation)
x = MsgBox("No Beeps", vbQuestion)
End Sub
And the "beeps" I hear appear to be tied to the system event sounds. So if I apply a sound to the system event "Question" using Control Panel>Sounds I can create a beep with vbQuestion.
vbInfomation = Asterisk
vbCritical = Critical Stop
vbExclamation = Exclamation
vbQuesiton = Question
vbQuestion as an argument will not generate a beep. Of course, you're stuck with a question mark graphic on your messagebox, which may or may not be desireable.
Sub TestMsgbox()
Dim x As Integer
x = MsgBox("Beeps")
x = MsgBox("Beeps", vbCritical)
x = MsgBox("Beeps", vbInformation)
x = MsgBox("Beeps", vbExclamation)
x = MsgBox("No Beeps", vbQuestion)
End Sub
Frosty
07-09-2011, 12:52 PM
Interesting... it does in 2003, regardless if the Tools > Options > General > Provide feedback with Sound is checked on or off.
I actually get totally different sounds depending on what argument I'm using, so my guess is that it's related to a system property.
In windows XP and Word 2003, it appears that the following is true:
Sub TestMsgbox()
Dim x As Integer
x = MsgBox("Beeps: Windows System Sound 'Asterisk'")
x = MsgBox("Beeps: Windows System Sound 'Critical Stop'", vbCritical)
x = MsgBox("Beeps: Windows System Sound 'Default Beep'", vbInformation)
x = MsgBox("Beeps: Windows System Sound 'Exclamation'", vbExclamation)
x = MsgBox("Beeps: Windows System Sound 'Question'", vbQuestion)
End Sub
So, the only reason the vbQuestion worked for me, is because my system didn't have a sound applied for that event.
So the answer may have been fairly incomplete above, and I'm going to guess Greg turned off his windows system sound asterisk at some point.
Always more to learn about this kind of stuff... how interesting. So you could actually temporarily change the system sound to give different sound effects for the default messagebox...
Frosty
07-09-2011, 12:52 PM
Hah, looks like Greg and I discovered mostly the same thing... I have different results with asterisk and default beep... but I'm on XP...
gmaxey
07-09-2011, 01:20 PM
Jason,
Actually I have a sound applied to "Asterisk" and "Default" but here on Windows 7 I don't get any beep with Msgbox "No Beep". Actually this makes sense as another form of construction is:
Msgbox "No beep", 0
My system defualt sound isn't used at all.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.