Microsoft KB Archive/287120

= How to automate Excel Text to Speech in another Office program =

Article ID: 287120

Article Last Modified on 10/23/2006

-

APPLIES TO


 * Microsoft Excel 2002 Standard Edition
 * Microsoft Outlook 2002 Standard Edition
 * Microsoft PowerPoint 2002 Standard Edition
 * Microsoft Word 2002 Standard Edition

-



This article was previously published under Q287120



IN THIS TASK
SUMMARY Use Text to Speech in PowerPoint
 * Insert a Module into a PowerPoint Presentation
 * Add a Reference to Excel 10 Object Library
 * Sub Procedure to Automate Excel Text to Speech from PowerPoint

Use Text to Speech in Word
 * Insert a Module into Word
 * Add a Reference to Excel 10 Object Library
 * Sub Procedure to Automate Excel Text to Speech from Word

REFERENCES



SUMMARY
This step-by-step article explains how you can use the Text to Speech functionality of Microsoft Excel in other programs, including Microsoft Word, Microsoft PowerPoint, and Microsoft Outlook.

Microsoft Excel is the only Microsoft Office XP program that has built-in Text to Speech (TTS) capabilities. This article explains how you can use OLE Automation to programmatically access the Excel object model and use the Text to Speech functionality in other programs.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

back to the top

Use Text to Speech in PowerPoint
The following example uses the Excel object model to access Text to Speech from a PowerPoint presentation. This procedure demonstrates how to reference and create an Excel object in order to use the Speech object.

back to the top

Insert a Module into a PowerPoint Presentation

 * 1) Open a PowerPoint presentation.
 * 2) Press ALT+F11 to start the Visual Basic Editor.
 * 3) On the Insert menu, click Module.
 * 4) Type or copy and paste into the module the sample code that appears later in this section.

back to the top

Add a Reference to Excel 10 Object Library

 * 1) In the Visual Basic Editor, point to References on the Tools menu.
 * 2) Under Available References, click to select the Microsoft Excel 10.0 Object Library check box, and then click OK.

back to the top

Sub Procedure to Automate Excel Text to Speech from PowerPoint
The following example assumes that your PowerPoint presentation has two slides. Sub demoTTS 'Declare and create an Excel object. Dim XL As Excel.Application Set XL = CreateObject(&quot;Excel.Application&quot;) ActivePresentation.SlideShowSettings.Run With SlideShowWindows(1).View 'The following is said on the first slide: XL.Speech.Speak &quot;Welcome to my presentation.&quot; 'Change to slide 2, and then say the following two sentences: .Next XL.Speech.Speak &quot;This is an example of how to create an Excel Application object.&quot; XL.Speech.Speak &quot;We can use Excel's object model to invoke Text to Speech.&quot; 'Close the Excel object and set the object to nothing. XL.Quit Set XL = Nothing 'Exit the slideshow. .Exit End With End Sub

NOTE: PowerPoint security is set at high by default. Unsigned Visual Basic macros do not run in this setting. Change the macro security level to medium by following these steps:
 * 1) On the Tools menu, point to Macro, and then click Security.
 * 2) On the Security Level tab, click to select Medium, and then click OK.
 * 3) On the File menu, click Exit to quit PowerPoint.

NOTE: You must quit and restart PowerPoint for the security level change to take effect.

back to the top

Use Text to Speech in Word
The following example uses the Excel object model to access Text to Speech from a Word document. This procedure demonstrates how to reference and create an Excel object in order to use the Speech object.

back to the top

Insert a Module into Word

 * 1) Open a Word document.
 * 2) Press ALT+F11 to start the Visual Basic Editor.
 * 3) On the Insert menu, click Module.
 * 4) Type or copy and paste into the module the sample code that appears later in this section.

back to the top

Add a Reference to Excel 10 Object Library

 * 1) In the Visual Basic Editor, point to References on the Tools menu.
 * 2) Under Available References, select the Microsoft Excel 10.0 Object Library check box, and then click OK.

back to the top

Sub Procedure to Automate Excel Text to Speech from Word
The following example assumes that you type text in your Word document and then select the text before you run the Sub procedure. Sub TTS 'Declare and create an Excel object. Dim XL_tts As Excel.Application Set XL_tts = CreateObject(&quot;Excel.Application&quot;) XL_tts.Speech.Speak Selection XL_tts.Quit Set XL_tts = Nothing End Sub NOTE: Word security is set at high by default. Unsigned Visual Basic macros do not run in this setting. Change the macro security level to medium by following these steps:
 * 1) On the Tools menu, point to Macro, and then click Security.
 * 2) On the Security Level tab, click to select Medium, and then click OK.
 * 3) On the File menu, click Exit to quit Word.

NOTE: You must quit and restart Word for the security level change to take effect.

back to the top