Making a Worksheet Talk Using Excel 2007 & VBA: Tech Tutorial

You might not have noticed, but Excel has a speech generator. You may also know that you use VBA to control the output generator. This is a fun tool to play around with and can bring excitement to your spreadsheets. It relieves me after my audience is overloaded with numbers, statistics, and charts. Just imagine going over a sales projection when the usual Microsoft voice comes over saying “$2,000 until the sales goal is reached!” A new type of study is coming to my audience.

The method by which this can be done is the method of Speaking. When a range is applied it will refer to cells per row or column. You can specify which part you want the behavior to be by using the:

expression. Speak (SpeakDirection

This can only be used if it is applied to a “Range” object.

The object that I will discuss in this article is the “Speech” object. There are several uses for it, and it varies in several ways You can. In the example of this article, we will first create a function that will define the talk method. p>

Application.Speech.Speak (txt

TalkIt = txt

End Function

If you have some programming or VBA experience, it’s not too difficult .you can see exactly what the function does. If you are new to VBA, we declared a new function, we named it TalkIt, and then we declared it to be a variable.

Function TalkIt

p>

by doing this, you can’t call the TalkIt function without passing all the parameters to it.Next, we called the speak method, starting with the Speech property of the application object.

Application.Speech.Speech. (txt

Finally, before closing the function, we set a value to the TalkIt function. This way, when the function code is executed, it will require the value of the variable ‘txt’ before the code executes.

But the function defined is, we’ll skip the opportunity to talk. You can do that by clicking on any part of the button. In this example, I’ll use the TalkIt function from the button

Private Sub Button_1(

Dim intTotal As Integer

intTotal = Worksheet.Sum(Cells.Range(“B3”, “B14”))

TalkIt (intTotal

OK, now to explain. Using the “click” event of the cmdCalculated button, we first defined the variable “intTotal” as an integer. Then we assigned cells A1:A10 the total value of the variable. Finally, we called the TalkIt function we created before and assigned the value of the variable intTotal to it If you put the numbers in the expansion in all the cells from A1 to A10, you will hear the voice say the sum of the cells. speaking phrases from the calculations. Simple enough; all you have to do is add two lines of code to cmdCalculations_Click under the row.

Private Sub cmdCalculate_Click(

Dim intTotal As Integer

‘ new variable to get the text

Dim txtTotal As String

intTotal = Worksheet Function.Sum(Cells.Range(“A1”, “A10”)

> “use the if… statement to control the value of the ‘txtTotal variable

If intTotal < 25000 Then

txtTotal = “Got not reached”

Else

txtTotal = “Goal Reached”

End If

TalkIt (txtTotal

End Sub

For the example above, if the sum of A1:A10 is greater than 25000 is, you will hear a voice saying “Goal Reached”; if not, then it will say “Goal Not Reached”. Play around with the numbers in the cells to hear both different responses. If nothing else, when you’re dealing with a long, drawn-out piece of code, you can be sure that it’s done correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *