Option Explicit
Public Sub Example()
Const strTitle As String = "Speech Demo - Message "
Dim eRslt As VBA.VbMsgBoxResult
VoiceBox "Though I speak with the tongues of men and of angels, and " & _
"have not charity I am nothing.", vbInformation, _
strTitle & "1"
Do
eRslt = VoiceBox("""Abort, Retry, Fail?"" was the phrase some " & _
"wormdog scrawled next to the door of the Edit " & _
"Universe project room. And when the new " & _
"dataspinners started working, fabricating their " & _
"worlds on the huge organic comp systems, we'd " & _
"remind them: if you see this message, always " & _
"choose ""Retry.""", vbQuestion + vbAbortRetryIgnore, _
strTitle & "2")
Select Case eRslt
Case VbMsgBoxResult.vbAbort
VoiceBox "Abortion takes a life.", title:=strTitle & "3"
End
Case VbMsgBoxResult.vbRetry
VoiceBox "Hell is repetition.", title:=strTitle & "4"
Case VbMsgBoxResult.vbIgnore
VoiceBox "There is no problem so great it can not be ignored." _
, title:=strTitle & "5"
Exit Do
End Select
Loop While eRslt = vbRetry
End Sub
Public Function VoiceBox(ByVal prompt As String, _
Optional ByVal buttons As VbMsgBoxStyle, _
Optional ByVal title As String, _
Optional ByVal helpFile As String, _
Optional ByVal context As Long) As VbMsgBoxResult
Dim spv As Object
Set spv = CreateObject("SAPI.SpVoice")
spv.Speak prompt, SVSFlagsAsync
VoiceBox = Msgbox(prompt, buttons, title, helpFile, context)
Set spv = Nothing
End Function
|