时间:2022-09-06 12:34:34
具体实现方法思路:制作一个点名页面,安排三个操作按钮,分别是“点名”、“缺”、“到”,并分别给这三个按钮赋予相应的VBA程序代码,完成相应的控制或记录任务。当开始点名时,老师点击“点名”按钮,让电脑按学生花名册信息自动语音点名,如果学生已到课,点击“到”按钮记录,如果学生缺课,点击“缺”记录。
首先要说明的是,Excel中的“文本到语音”功能不是默认安装的。打开“工具”菜单,选择“语音”项子菜单中的“显示文本到语音工具栏”命令,Excel会自动进行安装。安装好后,可以弹出“文本到语音”浮动工具栏。
以Excel 2003为例,具体实现步骤如下:
1.在工作表Sheet2中输入学生的点名册信息(图1)。
2.适当设置工作表Sheet1中单元格的格式,并在其上添加三个命令按钮,标题分别为“开始”、“缺”和“到”(图2)。
3.为三个命令按钮“开始”、“缺”和“到”编写单击事件过程,输入具体的VBA代码:
PrivateSubCommandButton1_Click()
'开始
With Sheet2
Cells(12,1)=.UsedRange.Columns.Count+1
Cells(13,1)=.UsedRange.Rows.Count-1
'记录点名人数
IfCells(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.SpeakCells(8,3)
'语音朗读姓名
CommandButton3.Activate
EndIf
EndWith
EndSub
PrivateSubCommandButton2_Click()
'缺
IfCommandButton2.EnabledThen
With Sheet2
.Cells(Cells(13,1)+1,Cells(12,1))="缺"
Cells(13,1)=Cells(13,1)-1
'点名人数递减
IfCells(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.SpeakCells(8,3)
'语音朗读姓名
CommandButton3.Activate
EndIf
EndWith
EndIf
EndSub
PrivateSubCommandButton3_Click()
'到
IfCommandButton3.EnabledThen
With Sheet2
.Cells(Cells(13,1)+1,Cells(12,1))=""
Cells(13,1)=Cells(13,1)-1
'点名人数递减
IfCells(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.SpeakCells(8,3)
'语音朗读姓名
EndIf
EndWith
EndIf
EndSub
点名开始前,“开始”命令按钮是可用的,而“缺”和“到”命令按钮都是不可用的。单击“开始”命令按钮后,把“缺”和“到”命令按钮设置为可用,而学生的学号和姓名会逐一显示在Sheet1中。根据学生的出勤情况分别单击“缺”或“到”命令按钮,把出勤情况记录在Sheet2中。在此过程中,Sheet1中显示的点名人数会逐渐递减,直至最后为0,表示点名完毕。