《在excel报表中使用语音提示》由会员分享,可在线阅读,更多相关《在excel报表中使用语音提示(2页珍藏版)》请在金锄头文库上搜索。
1、Option ExplicitDeclare Function sndPlaySound Lib “winmm.dll“ Alias “sndPlaySoundA“ (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long再在 Workbook 的 BeforeSave 事件中(根据需要也可以选用其他事件)加入下列用 VBA 编 写的宏代码:With Sheet1If .Range(“A2“).Value2 Or .Range(“A2“).Value-2 Then判断 A2 单元格内的数据是否大于 2 或小于负 2x% = sn
2、dPlaySound(“C:语音语音 01.wav“, uFlags%)播放语音文件“C:语音语音 01.wav”End IfIf .Range(“B2“).Value2 Or .Range(“B2“).Value-2 Then判断 B2 单元格内的数据是否大于 2 或小于负 2x% = sndPlaySound(“C:语音语音 02.wav“, uFlags%)播放语音文件“C:语音语音 02.wav”End IfEnd WithPrivate Sub Worksheet_Change(ByVal Target As Range) 如果输入后按回车, 可以实现逐个字符朗读 Dim lengt
3、h As Integer Dim i As Integer Dim strT As String Dim ch As String Dim intR As Integer, intC As Integer MsgBox “你修改了数据 “ intR = ActiveCell.Row intC = ActiveCell.Column If intR 0 Then strT = Cells(intR - 1, intC) length = Len(strT) If length 0 Then For i = 1 To length ch = Mid(strT, i, 1) Application.
4、Speech.Speak ch Next i End If End If End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) 如果单元 格在选定状态下按方向键,或者用鼠标改变活动单元格触发 Dim length As Integer Dim i As Integer Dim strT As String Dim ch As String Dim intR As Integer, intC As Integer intR = ActiveCell.Row intC = ActiveCell.Column If
5、intR 0 Then strT = Cells(intR - 1, intC) length = Len(strT) If length 0 Then For i = 1 To length ch = Mid(strT, i, 1) Application.Speech.Speak ch Next i End If End If End Sub Sub 输入() Dim length As Integer Dim i As Integer Dim strT As String Dim ch As String strT = ActiveCell.Text length = Len(strT) If length 0 Then For i = 1 To length ch = Mid(strT, i, 1) Application.Speech.Speak ch Next i End If End Sub