Displaying a Message and a Beep

  • Thread starter Thread starter ZAK
  • Start date Start date
Z

ZAK

Hi

Does anyone knwo how to display a message and set
continuous beeps at certain intervals.

I used message box but the problem is it waits for on to
click on the OK button, only then it proceeds to do the
beeps.

I want that happening simultaneously. Think mulitthreading
might be required here.

Regards

Yamin
 
Yamin,

To beep while a message is displayed, you'll need to
create UserForm and a procedure in a code Module.

To learn more about the techniques I have used, you
should look into the Application.OnTime method
and learn about UserForms.

Here's a step-by-step.

1. Start Excel with an empty workbook
2. Activate Visual Basic Editor by pressing Alt+F11
3. Insert - Module
4. Enter this code:

Dim BeepTime As Date

Sub BeepNow()
Beep
BeepTime = Now + TimeValue("00:00:01")
Application.OnTime _
EarliestTime:=BeepTime, _
Procedure:="BeepNow", _
Schedule:=True
End Sub

Sub UnBeep()
Application.OnTime _
EarliestTime:=BeepTime, _
Procedure:="BeepNow", _
Schedule:=False
End Sub

Sub ShowWarning()
UserForm1.Show
End Sub

5. Insert - UserForm

6. In the properties window (press F4 if you don't see it) change
the Caption of the UserForm to "Coffeine level warning"

7. Use the Toolbox to add a label and a CommandButton to your
form. Change the caption of the label to "You have missed your
coffee break" and the caption of the commandbutton to "OK"

8. Double-click anywhere on the form and add this code:

Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Call BeepNow
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Call UnBeep
End Sub


Now you are done. Press Alt+F11 to return to Excel.
Run the ShowWarning procedure (Tools - Macro - Macros...).
Happy?


Ture Magnusson
Karlstad, Sweden
 
Back
Top