Activate VBA Text to Speech (TTS) in Excel
In this article you will learn about these topics related to TTS in Excel.
These voice options are useful in Excel, Outlook or Word to read out the messages at background while we are busy with work.
You can make a whole lot of speech applications using the options presented here.
1. Install Text to Speech – SAPI
To make the speech controls to work, your system should have Win32 Speech API (SAPI) installed. It is also called Microsoft Speech SDK. Get it from here.
After installation, to make sure TTS is enabled in your machine check this option.
- Control Panel -> Speech Recognition -> Text To Speech.
Once this is enabled, you can make Excel, Word or Outlook applications to talk messages or text.
2. Add Speech Control in Excel Menu
Once the SAPI (or TTS) is installed, you can add speech controls to Excel Menu that are available in higher version of MS Office.
Steps to Add Speech Controls:
- From ‘Quick Access Tool bar’, Click More Controls
- Click ‘All Commands’ in drop down list of choose commands.
- Scroll down the list to get these options.
- Speak Cells
- Stop speaking cells
- Speak Cells by Columns
- Speak Cells by Rows
- Speak Cells on Enter
- Add the controls required & click ok.
This will add the controls to your Quick access Toolbar over the Menu. Read this link to get detailed explanation about TTS controls.
3. Excel VBA Text To Speech
3.1 Application.Speech.Speak in VBA
Wouldn’t it be nice if the computer actually speaks up & asks the user for info or notifies him with a voice message?
It increases the chances of user responding to the message more quickly. Let’s see, how to make the VBA use the TTS (Text to Speech) service and speak out the messages.
'Activate Voice Message Notification
Application.Speech.Speak "Message From VBA Macro"
'Read Data from Excel Sheet
3.2 Asynchronous Speech in VBA Application.Speak
Application.Speech.Speak Command – Parameters: Speak Function has 4 parameters. Refer MSDN library for detailed information of all the 4 parameters.
Here we will discuss about the SpeakAsync parameter which we might use it often. See the example below that depicts how SpeakAsync behaves when it is set to True or False.
'SpeakAsync is set to False. So, program execution will wait for the speech to complete
'and then proceed to next command.
Application.Speech.Speak "Wait for Speech to Complete", False
MsgBox "Wait for Speech to Complete"
'SpeakAsync is True. Program execution continues while Speech is in progress
Application.Speech.Speak "Proceed without Waiting for Completion", True
MsgBox "Display Message While Speech is in Progress"
In Short, this parameter decides whether the Program execution can continue or it has to wait till Speak Command Reads out the complete message.
Text to Speech (TTS) – Practical Uses:
It is always fun to have more media assisted applications that having the traditional Message box to provide information to the End user. Let’s use this option to get more user satisfaction.
- Live Updates: If User has any Excel application that constantly refreshes data, like Stock quotes, Sports Score Cards etc., it will be very useful if Excel provides Voice Updates.
- Task Tracker: If any task or Quiz has to be completes with in restricted Time, it will be nice if Excel updates through voice about Time remaining to complete the task.
- Remainder: It will be so handy in remainder services, with Voice assistance.
- Help: In Excel Applications, Voice Assisted help messages will be more helpful than help tips from Message box or Labels.
To display traditional method of error or information notification, we throw a ‘Message Box’ to User through a tiny pop-up window.To know how to create such notification messages using “Msgbox” command, refer this page which explains how to create your first Hello World VBA Program.
But, these message boxes will pop up at the background if the excel is not active. Chances are there that Users might miss to notice it If they are working on any other applications like IE, Word or Outlook.
If a task requires an urgent attention from User, then we can code our program to give an additional audible speech notification to get quick response.