在Ecel报表中使用语音提示.docx
OptionExplicit
DeclareFunctionsndPlaySoundLibwinmm.dllAliassndPlaySoundA(ByVallpszSoundNameAsString,ByValuFlagsAsLong)AsLong
再在Workbook的BeforeSave事件中(根据需要也可以选用其他事件)加入下列用VBA编写的宏代码:
WithSheet1
If.Range(A2).Value〉2Or.Range(A2).Value〈-2Then判断A2单元格内的数据是否大于2或小于负2
x%=sndPlaySound(C:\语音\语音01.wav,uFlags%)播放语音文件“C:\语音\语音01.wav”
EndIf
If.Range(B2).Value〉2Or.Range(B2).Value〈-2Then判断B2单元格内的数据是否大于2或小于负2
x%=sndPlaySound(C:\语音\语音02.wav,uFlags%)播放语音文件“C:\语音\语音02.wav”
EndIfEndWith
Private Sub Worksheet_Change(ByVal Target As Range)如果输入后按回车,可以实现逐个字符朗读
Dim length As IntegerDim i As Integer
Dim strT As StringDim ch As String
Dim intR As Integer, intC As IntegerMsgBox 你修改了数据
intR = ActiveCell.RowintC = ActiveCell.ColumnIf intR 0 Then
strT = Cells(intR - 1, intC)
length = Len(strT)
If
length
For
0 Then
i = 1 To length
ch = Mid(strT, i,
1)
Application.Speech.Speak
ch
Next
i
End
If
End
If
End
Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
格在选定状态下按方向键,或者用鼠标改变活动单元格触发
Dim length As IntegerDim i As Integer
Dim strT As StringDim ch As String
Dim intR As Integer, intC As IntegerintR = ActiveCell.Row
intC = ActiveCell.ColumnIf 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 IntegerDim i As Integer
Dim strT As StringDim ch As StringstrT = ActiveCell.Textlength = Len(strT)
If
length
For
0
i =
Then
1 To length
ch
= Mid(strT, i,
1)
Application.Speech.Speak ch
Next i
End If
End Sub
如果单元