Use Microsoft Speech

What can you learn here ?
  • Use microsoft SAPI
  • Access from any VBA
  • Office text to speech

Converting text to speech in VBA

In Excel you can use the Application.Speech.Speak method to convert a string to Speech. Here's how to use the Microsoft Speech API  in VBA in Outlook, Word etc.

Add a reference to the SAPI


Create a general procedure to use.

Public Sub say(sTerm As String)
    Dim spv As Object
    Set spv = CreateObject("SAPI.SpVoice")
    spv.Speak sTerm
    Set spv = Nothing
End Sub

Use it

In this case, A tagCloud in Outlook will say the tagCloud, as well as displaying it.

    With mailItem
        .Subject = tg.tagJob.key
        .BodyFormat = olFormatHTML
        .HTMLBody = tg.htmlResults
        .Display (False)
        say .Body
    End With

Comments