In Excel VBA, MsgBox has no argument for choosing or setting a sound. On Windows, a message box with an alert icon may play the sound assigned to that icon by the system; if you need a separate beep, use VBA’s Beep statement or a Windows-specific sound API.
How MsgBox sound works
The built-in MsgBox function displays a modal dialog: VBA pauses the current procedure until the user responds. Its arguments let you set the message, buttons, icon, title, and optional help information. There is no sound filename, volume, pitch, or “play sound” parameter in that list.
On Windows, the icon style can be associated with a system alert sound. For example, vbExclamation displays a warning-style icon and may trigger the warning sound, while vbInformation uses an information icon and may trigger the corresponding system sound. The operating system’s sound scheme and current audio settings affect what the user actually hears. A sound may be disabled, muted, or routed somewhere unexpected, so an icon is not a guarantee of audible output.
A plain message box with no icon generally should not be treated as a reliable way to play an alert tone. Also, a sound heard when a dialog appears is not a separate capability of the VBA MsgBox function; it is associated with the host operating system’s handling of that dialog.
Choose a message-box icon
For routine Excel messages, choose an icon that accurately describes the situation rather than selecting one just to get a particular sound. The icon helps people understand the message, and Windows may associate it with a system sound.
vbInformation: an informational message, such as a completed export.vbExclamation: a warning that calls for attention but does not necessarily mean an operation failed.vbCritical: a serious error or a condition that prevents the requested action.vbQuestion: a prompt asking the user to make a choice. It does not mean the message is a warning.
These constants are used in the buttons-and-icon argument. For example, vbOKOnly Or vbInformation combines an OK button with an information icon. Use Or to combine compatible button and icon constants. A simple example is:
Sub ShowCompletionMessage()
' Display a completion message with an information icon.
MsgBox "The report is ready.", vbOKOnly Or vbInformation, "Complete"
End Sub
The code asks Windows to show an information-style message box; it does not specify a particular sound. Before running any macro, save a copy of the workbook: VBA macros cannot be undone with Ctrl+Z.
Add a beep before or after the dialog
VBA’s Beep statement requests a basic beep independently of the message-box icon. Put it immediately before the dialog if you want the tone first, or after the dialog if the user should hear it only after dismissing the message. The statement does not offer controls for a sound file, duration, volume, or melody, and the result depends on the computer’s audio configuration.
Sub AlertBeforeMessage()
Dim answer As VbMsgBoxResult
' Request a basic system beep, then show the prompt.
Beep
answer = MsgBox("Continue with the import?", vbYesNo Or vbQuestion, "Confirm import")
End Sub
Because MsgBox is modal, the procedure waits at that line until the user chooses a button. In this example, the beep is requested before the prompt appears. The variable answer stores the result, so code can respond to vbYes or vbNo afterward. If you do not need the response, you can call MsgBox without assigning its result.
Use a beep sparingly. Repeated tones can annoy users, and a tone alone does not explain what action is needed. Pair it with clear text and an appropriate icon; do not rely on sound as the only way to communicate an important warning.
Use a Windows system sound when you need more control
For a Windows-only workbook, VBA can call the Windows MessageBeep API to request a system sound type. This still uses system sounds rather than playing an arbitrary audio file, and the user’s sound settings can affect whether it is audible. The declaration below supports VBA 7, used by current Microsoft 365 Excel, and includes a conditional declaration for older VBA versions. Put it in a standard module in Excel for Windows:
#If VBA7 Then
Private Declare PtrSafe Function MessageBeep Lib "user32" (ByVal uType As Long) As Long
#Else
Private Declare Function MessageBeep Lib "user32" (ByVal uType As Long) As Long
#End If
Sub PlayInformationSound()
Dim result As Long
' Request the Windows information sound.
result = MessageBeep(&H40)
End Sub
The value &H40 requests the information-style system sound. Other documented values correspond to other standard sound types; they do not let you choose a custom WAV or MP3 file. The return value indicates whether the API call succeeded, not whether a person could hear it. This declaration depends on the Windows user32 library and is not portable to Excel for Mac. Do not add it to a workbook intended to run across Windows and Mac unless you provide platform-specific handling.
Why a MsgBox may be silent
If a message box appears but no sound is heard, the dialog itself may be working normally. Check the likely causes before changing the macro:
- No sound-triggering icon: A message box without an alert icon may not request the sound you expect. Add an appropriate icon only if it fits the message.
- System sounds are disabled or muted: Windows sound schemes can assign no sound to an event. In Windows, check the classic Sound control panel’s Sounds tab; the route to it can vary by Windows version.
- Excel or the output device is muted: Check the Windows volume mixer, selected output device, headset connection, and speaker volume.
- Remote or virtual desktop settings: Remote-session audio policies may redirect, suppress, or disable sound.
- Platform differences: Excel for Mac does not use the Windows sound scheme or Windows API. Excel for the web does not run VBA macros at all.
Try a familiar Windows notification sound outside the workbook and check whether other applications can play audio. If other system sounds are also silent, the problem is probably in Windows or the audio setup rather than the VBA statement. If only the macro’s alert is missing, confirm the icon constant and test the workbook on the intended platform.
Windows, Mac, and Excel for the web
On Excel for Microsoft 365 on Windows, VBA macros can display MsgBox dialogs, and Windows controls the system sound behavior associated with them. The MessageBeep example above is specifically for Windows. If the workbook may be used on Mac, a Windows API declaration can fail to compile or run there, so avoid making it part of a cross-platform procedure without checking the operating system first.
Excel for Mac supports VBA, but its dialogs and audio behavior are not governed by the Windows sound scheme. Do not assume that an icon will produce the same sound on both platforms, and do not use user32 calls in Mac-targeted code. Excel for the web cannot execute VBA; users need the desktop application to run a macro. These distinctions matter when a sound is part of a workflow rather than an optional notification.
Sound versus accessibility and usability
A sound can draw attention, but it is not a substitute for a descriptive message. Some users work with muted speakers, use assistive technology, or cannot reliably distinguish alert tones. Make the text itself state what happened and what the user should do next. For example, “The file could not be imported. Check that it is a .xlsx workbook and try again” is more useful than “Error.”
Also avoid using a critical icon or alarming sound for routine success messages. Overstated alerts can make users ignore messages that genuinely need attention. If the notification is frequent or non-blocking, a status-bar update or a cell-based status indicator may be less disruptive than a modal dialog that stops the macro and requires a click.
Alternatives to MsgBox sounds
Choose the notification method based on what the user needs to know. A message box works well when the user must read a short message or make a choice before the macro continues. A basic Beep is suitable only for a simple tone where no sound customization is needed. A Windows API call can request a standard Windows sound but ties the solution to Windows.
- Use a clear message and an appropriate icon for a short, important alert.
- Use a worksheet status cell or the Excel status bar for progress or routine completion information.
- Use a UserForm when a workflow needs a more designed interface or several choices.
- For custom audio, use a platform-appropriate method and test it on the computers where the workbook will run; VBA has no cross-platform MsgBox sound-file argument.
For shared workbooks, explain any platform requirement and provide a useful text-based fallback. A sound should enhance the notification, not be necessary to understand or complete the task.
Frequently Asked Questions
Can I set a sound directly in the VBA MsgBox function?
No. MsgBox has no sound or sound-file argument. You can choose an icon, use Beep, or call a platform-specific sound API.
Does vbExclamation always make a sound?
No. It selects a warning-style icon, which Windows may associate with a system sound. The sound scheme, mute state, audio device, and environment can prevent it from being heard.
How do I make a MsgBox beep in Excel VBA?
Put the VBA statement Beep immediately before or after the MsgBox call. It requests a basic beep but does not let you select a custom tone or guarantee audible output.
Can I play a custom WAV or MP3 from MsgBox?
Not through MsgBox itself. A custom sound requires a separate playback method, which may depend on Windows or another platform-specific component; test compatibility before distributing the workbook.
Will VBA MsgBox sound work on Mac or Excel for the web?
Do not expect Windows-style message sounds or Windows API calls to work on Mac. Excel for the web does not run VBA macros, so the macro and its dialog are unavailable there.
Related
- Microsoft Excel Scenario Manager: Setup, Uses, and Limits
- Microsoft Excel: Remove Page Break Lines and Hide Them
- Microsoft Excel Scatter Plot: How to Create and Read One
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Filter Function: Syntax, Examples, and LimitsIn Excel VBA, the Filter function searches a one-dimensional array of strings and returns the elements that contain…
- Excel UserForm ComboBox: Load a List with VBATo load an Excel UserForm ComboBox from worksheet values, add a ComboBox to the form, then fill it…
- VBA Dictionary: How to Create and Use OneYes. In VBA, a dictionary is a key-value object that lets you store a value under a unique…
- Excel VBA GoTo: Syntax, Examples, and Error HandlingIn Excel VBA, GoTo transfers execution to a named label elsewhere in the same procedure. It is most…
- VBA Range Filter: How to Use AutoFilterTo filter a worksheet range with VBA in Excel for Microsoft 365 on Windows, call the range’s AutoFilter…
- VBA Create Word Document From TemplateTo create a Word document from a template with VBA, call Word’s Documents.Add method with the template’s full…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.