Option Explicit
'--------------------------------------------------------------------------------
' Procedure : Example
' Author : Aaron Bush
' Date : 9/9/2008
' Purpose : To demonstrate simple usage of the Microsoft Speech Object Library
' Revisions : Aaron Bush 9/9/2008 Initial Creation.
'--------------------------------------------------------------------------------
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
'From Sid Meier's Alpha Centauri, please don't sue me Sid.
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
'--------------------------------------------------------------------------------
' Procedure : VoiceBox
' Author : Aaron Bush
' Date : 9/9/2008
' Purpose : Provides a message box that uses the Microsoft Speech API (SAPI)
' to speak the contents of the message box. This has the advantage
' of working across multiple applications without alteration (as
' opposed to Excel.Application.Speech.Speak).
' Input(s) : All inputs are the exact same as the standard MsgBox Function.
' Output(s) : Output will be an indicator of the users response.
' Revisions : Aaron Bush 9/9/2008 Initial Creation.
'--------------------------------------------------------------------------------
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
'For Early Bound object set a reference to Microsoft Speech Object Library:
'C:\Windows\System32\Speech\Common\sapi.dll
'Dim spv As SpeechLib.SpVoice
'Set spv = New SpeechLib.SpVoice
'Late Bound example follows:
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
|