当前位置:文档之家› 用VBA实现课堂语音点名 代码

用VBA实现课堂语音点名 代码

用Excel VBA实现课堂语音点名
广州 梁里宁

在学校从事教学工作的教师,上课时需要对学生的出勤情况进行检查,常常采用的是课堂点名的方式。而Excel中“文本到语音”的功能,能使Excel将单元格中的数字或文本内容朗读出来。通过VBA调用这一功能可实现课堂语音点名,摆脱了人工点名的传统方式,减轻了教师的点名负担。

具体实现方法思路:制作一个点名页面,安排三个操作按钮,分别是“点名”、“缺”、“到”,并分别给这三个按钮赋予相应的VBA程序代码,完成相应的控制或记录任务。当开始点名时,老师点击“点名”按钮,让电脑按学生花名册信息自动语音点名,如果学生已到课,点击“到”按钮记录,如果学生缺课,点击“缺”记录。

首先要说明的是,Excel中“文本到语音”的功能不是默认安装的。打开“工具”菜单,选择“语音”项子菜单中的“显示文本到语音工具栏”命令, Excel会自动进行安装。安装好后,可以弹出“文本到语音”浮动工具栏。

以Excel 2003为例,具体实现步骤如下:

1.在工作表Sheet2中输入学生的点名册信息(图1)。
2.适当设置工作表Sheet1中单元格的格式,并在其上添加三个命令按钮,标题分别为“开始”、“缺”和“到”(图2)。
3.为三个命令按钮编写单击事件过程,具体的VBA代码如图(图3、图4、图5):

Private Sub CommandButton1_Click()
'开始
With Sheet2
Cells(12, 1) = .UsedRange.Columns.Count + 1
Cells(13, 1) = .UsedRange.Rows.Count - 1
'记录点名人数
If Cells(13, 1) > 0 Then
.Cells(1, Cells(12, 1)) = Date
'记录点名日期
.Cells(1, Cells(12, 1)).ColumnWidth = 10
CommandButton2.Enabled = True
CommandButton3.Enabled = True
CommandButton3.Activate
Cells(5, 3) = .Cells(Cells(13, 1) + 1, 1)
'显示学号
Cells(8, 3) = .Cells(Cells(13, 1) + 1, 2)
'显示姓名
Application.Speech.Speak Cells(8, 3)
'语音朗读姓名
CommandButton3.Activate
End If
End With
End Sub

Private Sub CommandButton2_Click()
'缺
If CommandButton2.Enabled Then
With Sheet2
.Cells(Cells(13, 1) + 1, Cells(12, 1)) = "缺"
Cells(13, 1) = Cells(13, 1) - 1
'点名人数递减
If Cells(13, 1) = 0 Then
MsgBox "点名完毕!"
Cells(5, 3) = "点名请单击"
Cells(8, 3) = "开始按钮"
CommandButton1.Activate
CommandButton2.Enabled = False
CommandButton3.Enabled = False
Else
Cells(5, 3) = .Cells(Cells(13, 1) + 1, 1)
'显示下一个的学生
Cells(8, 3) = .Cells(Cells(13, 1) + 1, 2)
Application.Speech.Speak Cells(8, 3)
'语音朗读姓名
CommandButton

3.Activate
End If
End With
End If
End Sub

Private Sub CommandButton3_Click()
'到
If CommandButton3.Enabled Then
With Sheet2
.Cells(Cells(13, 1) + 1, Cells(12, 1)) = ""
Cells(13, 1) = Cells(13, 1) - 1
'点名人数递减
If Cells(13, 1) = 0 Then
MsgBox "点名完毕!"
Cells(5, 3) = "点名请单击"
Cells(8, 3) = "开始按钮"
CommandButton1.Activate
CommandButton2.Enabled = False
CommandButton3.Enabled = False
Else
Cells(5, 3) = .Cells(Cells(13, 1) + 1, 1)
'显示下一个的学生
Cells(8, 3) = .Cells(Cells(13, 1) + 1, 2)
Application.Speech.Speak Cells(8, 3)
'语音朗读姓名
End If
End With
End If
End Sub

点名开始前,“开始”命令按钮是可用的,而“缺”和“到”命令按钮都是不可用的。单击“开始”命令按钮后,把“缺”和“到”命令按钮设置为可用,而学生的学号和姓名会逐一显示在Sheet1中,根据学生的出勤情况分别单击“缺”或“到”命令按钮,把出勤情况记录在Sheet2中。在此过程中,Sheet1中显示的点名人数会逐渐递减,直至最后为0,表示点名完毕。



相关主题
文本预览
相关文档 最新文档