Excel

Play Different Beeps

Ease of Use

Easy

Version tested with

2000, 2002 

Submitted by:

Justinlabenne

Description:

Function that can easily the type of windows Beep style 

Discussion:

Can be used to easily switch between the type of windows beeps that are available. If your code utilizes an error handler, you can use a windows beep in your code that sounds when an error occurs, or another type when your code completes successfully as another helpful way to distinguish what is happening / happened when your code ends. 

Code:

instructions for use

			

Option Explicit 'API Declaration Private Declare Function MessageBeep& Lib "user32" (ByVal wType As Long) 'Enumeration of the beep types Public Enum BeepTypes MB_OK = &H0& MB_ICONASTERISK = &H40& MB_ICONEXCLAMATION = &H30& MB_ICONHAND = &H10& End Enum Public Function BeepType(lSound As BeepTypes) As Long ' Function to return BeepType = MessageBeep(lSound) End Function Sub TestTheBeep() ' Play the beep BeepType MB_ICONHAND End Sub

How to use:

  1. Open an Excel Workbook
  2. Copy the code
  3. Press Alt + F11 to open the Visual Basic Editor (VBE)
  4. Select INSERT > MODULE from the menubar
  5. Paste code into the right pane
  6. Press Alt+Q to return to Excel
  7. Save workbook before any other changes
 

Test the code:

  1. Go to TOOLS > MACRO > MACROS
  2. When the dialog appears, select (TestTheBeep)
  3. Press Run
 

Sample File:

Beep.zip 7.62KB 

Approved by mdmackillop


This entry has been viewed 262 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express