Sound With Message Box

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
982
Office Version
  1. 2021
Platform
  1. Windows
Code:
Sub Delete_Column()

With Worksheets("Sheet1")
    If Range("D1") <> "Percentage" Then
        MsgBox "Please Run Program First"
        Exit Sub
        Else: Columns("D:D").Delete
    End If
End With


End Sub

Hello All...
Quick Question:
How do I get sound, when the Message Box is displayed?
Thanks for the help
excel 2010
 
You can use
Code:
MsgBox "Please Run Program First", vbCritical

or
Code:
MsgBox "Please Run Program First", vbExclamation

to get one of the system sounds.
 
Upvote 0
Code:
Option Explicit


Private Declare Function sndPlaySound32 Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName _
As String, ByVal uFlags As Long) As Long


Sub Delete_Column()
    Dim PlaySound As Boolean


With Worksheets("Sheet1")
    If Range("D1") <> "Percentage" Then
        MsgBox "Please Run Program First"
        Exit Sub
        Else: Columns("D:D").Delete
        Call sndPlaySound32("C:\windows\media\chord.wav", 1)


    End If
End With




End Sub
 
Upvote 0
I like the vbExclamation better...Thanks for the help
 
Upvote 0
Neither vbCritical nor vbExclamation work on my Mac, I have to use the work-around

Code:
Beep
MsgBox "Please Run the program"
 
Upvote 0
Hi Guzzlr

I hope this works for you

Code:
With Worksheets("Sheet1")
    If Range("D1") <> "Percentage" Then
        Application.Speech.Speak "Please Run Program First"
        Exit Sub
        Else: Columns("D:D").Delete
    End If
End With

ColdGeorge
 
Upvote 0
Hi all

This one is even a little better

Code:
With Worksheets("Sheet1")
    If Range("D1") <> "Percentage" Then
        MsgBox "Please Run Program First"
        Application.Speech.Speak "Please Run Program First"
        Exit Sub
        Else: Columns("D:D").Delete
    End If
End With

ColdGeorge
 
Last edited:
Upvote 0
Code:
With Worksheets("Sheet1")
    If Range("D1") <> "Percentage" Then
        MsgBox "Please Run Program First"
        Application.Speech.Speak "Please Run Program First"
        Exit Sub
        Else: Columns("D:D").Delete
    End If
End With

This is interesting, an actual voice. The problem is the voice happens after the msg box is closed, after OK is selected. It would be cool to have the voice happen the same time the msgbox is displayed.
Thanks
 
Last edited:
Upvote 0
It would be cool to have the voice happen the same time the msgbox is displayed.

Try this :

Code:
Option Explicit

#If VBA7 Then
    Private Declare PtrSafe Function SetTimer Lib "user32" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr
    Private Declare PtrSafe Function KillTimer Lib "user32" (ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr) As Long
#Else
    Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
#End If


Sub Delete_Column()
    With Worksheets("Sheet1")
        If Range("D1") <> "Percentage" Then
            SetTimer Application.hwnd, 0, 100, AddressOf VoiceMessage
            MsgBox "Please Run Program First"
            Exit Sub
            Else: Columns("D:D").Delete
        End If
    End With
End Sub


Sub VoiceMessage()
    KillTimer Application.hwnd, 0
    Application.Speech.Speak "Please Run Program First"
End Sub
 
Last edited:
Upvote 0

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