Sound on msg box

sumsaam

Board Regular
Joined
Dec 31, 2012
Messages
82
Office Version
  1. 2010
Platform
  1. Windows
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)

Const SCAN_CELL As String = "K2"
Const RANGE_BC As String = "B2:B5000"
Dim val, f As Range, rngCodes As Range, qty As Variant, QtyMode As Boolean

If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range(SCAN_CELL)) Is Nothing Then Exit Sub

val = Trim(Target.Value)
If Len(val) = 0 Then Exit Sub

QtyMode = Me.Shapes("Check Box 1").OLEFormat.Object.Value = 1

If QtyMode Then qty = Application.InputBox(prompt:="Enter the Qty of  " & val, Title:="Quantity box", Default:=1, Type:=1)

If Not qty Then
    Set rngCodes = Me.Range(RANGE_BC)
    Set f = rngCodes.Find(val, , xlValues, xlWhole)
        If Not f Is Nothing Then
            With f.Offset(0, 2)
                .Value = .Value + IIf(QtyMode, qty, 1)
            End With
        Else
            'This if block asks to add or not if non listed barcode scanned
            If MsgBox("Item is out of List, add anyway?", vbYesNo + vbInformation, val) = vbYes Then
                Set f = rngCodes.Cells(rngCodes.Cells.Count).End(xlUp).Offset(1, 0)
                f.Value = val
                f.Offset(0, 1).Value = "enter description"
                f.Offset(0, 2).Value = IIf(QtyMode, qty, 1)
            End If
            'This if block asks to add or not if non listed barcode scanned
    End If
End If

Application.EnableEvents = False
Target.Value = ""
Application.EnableEvents = True

Target.Select

End Sub
i want a critical or exclamaition sound on message box appear. thank you
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Is this what you want ?

VBA Code:
Sub ExclamationWithMessageBox()
    Application.Speech.Speak "Exclamation"
    MsgBox "Hello"
End Sub
 
Upvote 0
or perhaps

VBA Code:
'place declaration at top of a module
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

'use like this
Sub SoundBeforeMessageBox()
    sndPlaySound "C:\Windows\Media\Alarm01.wav", 0
    MsgBox "Hello"
End Sub
 
Upvote 0
another one

VBA Code:
Sub BeepWithMessageBox()
    Beep
    MsgBox "Hello"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top