Skip to main content

Excel VBA Speak method




Microsoft has provided an Speech Object Library that can easily be referenced using  Excel VBA.

To add a reference to Microsoft Speech Object Library on Excel.

Open the Developer tab or press "ALT + F11".

Or check out this link to open the developer tab:

On the VBA window, click on "Tools" and click on "References".

And add the "Microsoft Office Speech Object Library".

See image below on how to add references in excel.


If Microsoft Office Speech Object Library is not added, VBA will throw a Compile error, "User-defined type not defined".

Once the reference has been added, create a new macro.

Click on the modules folder, on the VBA project window and add the code below:

Uncomment the line to test different voices.

====================================
Option Explicit

Private V As SpeechLib.SpVoice

Private T As SpeechLib.ISpeechObjectToken



Sub VBAspeak()

 

Dim strVoice As String

Dim xMessage As String

Set V = New SpVoice





        Set V.Voice = V.GetVoices().Item(1)

        'Set V.Voice = V.GetVoices().Item(2)  '--item number will change the voice

        'Set V.Voice = V.GetVoices().Item(0)  '--item number will change the voice

       

        xMessage = "hello, hello! I need some coffee."


'V.Speak xMessage , SVSFNLPSpeakPunc

'V.Speak xMessage, SVSFPurgeBeforeSpeak

V.Speak xMessage, SVSFDefault


End Sub

====================================
Check out this link on how to use Text to Speech on Microsoft word:

To learn further about Microsoft Speech feature see links below:



Cheers!!! Hope you make fun of the speech feature of  VBA.

Comments