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
 
Code:
With Worksheets("Sheet1")    If Range("D1") <> "Percentage" Then
        Application.Speech.Speak "Please Run Program First", SpeakAsync = False
        MsgBox "Please Run Program First"
        Exit Sub
        Else: Columns("D:D").Delete
    End If
End With

Got it...this makes the speech happen the same time the box is displayed. I also found an interesting article on-line of how to change speech and sound.
Thanks for the help.

Make Excel Talk with Application.Speech.Speak VBA - wellsr.com
 
Upvote 0
Code:
With Worksheets("Sheet1")    If Range("D1") <> "Percentage" Then
        Application.Speech.Speak "Please Run Program First", SpeakAsync = False
        MsgBox "Please Run Program First"
        Exit Sub
        Else: Columns("D:D").Delete
    End If
End With

Got it...this makes the speech happen the same time the box is displayed. I also found an interesting article on-line of how to change speech and sound.
Thanks for the help.

Make Excel Talk with Application.Speech.Speak VBA - wellsr.com

Nice !
I didn't know about the handy SpeakAsync argument ... Although it should be set to TRUE not to False.
 
Upvote 0
Code:
[COLOR=#333333]Although it should be set to TRUE not to False.[/COLOR]

This is the little backwards part of the way my code is written, according to the article, it should be set to TRUE. However, when set to True, the voice still runs after the msgbox is closed, because (I think) the program is stalled until the OK box is clicked and the program resumes.
Setting it to False, with the speech line before the msgbox, allows the macro to run that particular line of code and then to the msgbox line.
So, technically, the speech doesn't happen at the same time, but slightly ahead of the msgbox line, which happens so fast it appears to happen at the same time...at least that's my guess.

Actually, now that I think about it, if I set the speech line before the msgbox line, I would not need the SpeakAsync anyway...
Thanks
 
Last edited:
Upvote 0
Code:
[COLOR=#333333]Actually, now that I think about it, if I set the speech line before the msgbox line, I would not need the SpeakAsync anyway...[/COLOR]

Well that didn't work. Without the SpeakAsync, and the Speech line before the msgbox line, the speech talks, first, and then the msg box appears.
I'll keep it at False, which makes it appear the Speech & the Msgbox happen at the same time
 
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