Text-to-Speech in Excel

Posted Sun, Mar 27 2011 20:57 by Nate Oliver
Good evening,
 
Tonight, we'll look at a brief introduction of text-to-speech in Excel. I've been playing around with this since Excel XP, perhaps earlier, and it wasn't stable - it looks stable in 2010. I'll start with my set-up then explain. First, I placed the following contents in A1:A7:
Hello
World,
My
Name
Is
Nathan Oliver,
Cheers!
Next, I set up a module with the following code:
Private Declare Sub Sleep Lib "kernel32" ( _
    ByVal dwMilliseconds As Long)
 
Sub foo()
Dim cl As Range
For Each cl In Range("A1:A7")
    Application.Speech.Speak cl.Text
Next
End Sub
 
Sub bar()
Dim cl As Range
For Each cl In Range("A1:A7")
    Application.Speech.Speak cl.Text
    Call Sleep(3000)
Next
End Sub
 
Sub baz()
Dim cl As Range
For Each cl In Range("A1:A7")
    Application.Goto cl
    With cl.Interior
        .Color = 65535
        .Pattern = xlSolid
    End With
    Application.Speech.Speak cl.Text
    Call Sleep(3000)
    cl.Interior.Pattern = xlNone
Next
Application.Goto Range("A1")
MsgBox "We're done!"
End Sub
Okay, so what is happening, here? The first routine, foo(), simply rolls through the range, reciting the text. Now we have our base. Let's build in a 3-second delay, though, which bar() does. I was having trouble with the Excel Wait Method, so I leaned on an old friend, the Sleep() API call - works well. We have our 3-second delay.
 
From here we can get more creative, as baz() does, highlighting each cell, with a 3-second delay, for presentation purposes. Why would you want to do this? To present a talking a P&L or Balance Sheet to your boss who doesn't care for Spreadsheets, you could theoretically read off chart points, etc... The application is widespread, and limited to the imagination, only.
 
Cheers,
Nate Oliver

P.S. - I'm attaching a file, just in case you want to see what I did.
Attachment: Text_To_Speech.xls

Comments

# re: Text-to-Speech in Excel

Monday, March 28, 2011 2:02 PM by Patrick Matthews

Nate,

Thanks for this.  BTW, it appears that Excel will "speak" even when you slip Speak into a UDF called from a cell formula.

For example:

Function Foo()

   Foo = 42

   Application.Speech.Speak "Forty-two"

End Function

If you then use:

=Foo()

in a formula, then every time that cell calculates Excel will speak.  You could REALLY drive your users batty by making it volatile:

=Foo()*NOW()/NOW()

Patrick

# re: Text-to-Speech in Excel

Monday, March 28, 2011 5:58 PM by Nate Oliver

Wow, nice call, Patrick. You could make it even more irritating by returning a 0-length String and simply making the UDF volatile, e.g.,

Public Function fugazi() As String
With Application
   .Volatile
   .Speech.Speak "Gooney goo goo!"
End With
End Function

With usage as such:

=fugazi()

The end-user would never even see that thing, eh?

-Nate

P.S. - the unstable variety I worked on was with Excel 2000.

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: