April 2006
Beginner
1114 pages
98h 16m
English
Speech is fun to demo, but it’s not really a mainstream feature. Most often it is used to enable people with disabilities to read spreadsheets, but you can use it to read any text. For example, the following code reads comments aloud whenever a cell with a comment receives focus:
' ThisWorkbook object
Dim WithEvents g_app As Application
' Hook up the global Application object handler when this
' workbook opens.
Private Sub Workbook_Open( )
If Not (g_app Is Nothing) Then _
Set g_app = Application
End Sub
' Read comments aloud when cell is selected.
Private Sub g_app_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)
' If the cell has a comment.
If Not (Target.Comment Is Nothing) Then
On Error Resume Next
' Read the comment text aloud.
Application.Speech.Speak Target.Comment.Text
End If
End Sub
' Unhook handler
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set g_app = Nothing
End SubIt is important to turn on error handling in case speech is not installed on the user’s system.
Read now
Unlock full access