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.