ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 22215|回复: 41

[原创]WORD中的打字游戏程序

[复制链接]

TA的精华主题

TA的得分主题

发表于 2004-8-20 04:58 | 显示全部楼层 |阅读模式

zYGD4Fgl.rar (27.21 KB, 下载次数: 1063)

这是一款结合WORD实际与用户窗体制作的打字练习程序希望大家能喜欢。

pw:shourou

TA的精华主题

TA的得分主题

 楼主| 发表于 2004-8-20 05:04 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

注意:请将两个文件夹解压在同一文件夹下。

以下为源代码:

Private Sub CommandButton1_Click() Dim MyRange As Range, YwRange As String, i As Range, n As Range, Ect As Integer Dim Xct As Integer, Zz As String On Error GoTo ErrHandle If Me.CommandButton1.Caption = "Start" Then Application.ScreenUpdating = False TF = True Documents.Open FileName:=ActiveDocument.Path & "\练习文章.doc" Application.Windows("练习文章.doc").Visible = False StTime = Now Me.CommandButton1.Caption = "End" Rn = Int(Rnd() * 3000 + 1) Ys = Rn Set YText = Documents("练习文章.doc").Content Me.TextBox1.SetFocus Me.TextBox1 = Mid(YText, Rn, 30) MsgBox "您准备好了吗?第一个文字为(" & Mid(YText, Rn, 1) & ")开始!" Documents("打字游戏.doc").Activate ActiveDocument.Content.Delete CountText = Selection.Start Me.TextBox2 = "" Me.TextBox3 = "" Me.TextBox4 = "" WaitTime Else Me.CommandButton1.Caption = "Start" EnTime = Now TF = False Sd = Application.Selection.Start Set MyRange = ActiveDocument.Range(0, Sd) YwRange = Documents("练习文章.doc").Range(Ys - 1, Ys + Sd) For Each i In MyRange.Characters Xct = Xct + 1 Zz = Mid(YwRange, Xct, 1) If i <> Zz Then Ect = Ect + 1 Next Me.TextBox2.Value = Format(1 - Ect / Sd, "0.00%") Me.TextBox3.Value = Format(CDate(EnTime - StTime), "H:MM:ss") Me.TextBox4 = Round(Sd / ((EnTime - StTime) * 24 * 60)) & "(录入" & Sd & "字)" StTime = 0 EnTime = 0 Sd = 0 Rn = Empty Set YText = Nothing Application.ScreenUpdating = True Exit Sub ErrHandle: MsgBox "该程序出现不可预测错误,将被关闭,请在退出后重新打开该程序!" Application.Quit False End If End Sub Private Sub UserForm_Initialize() Me.Caption = "打字练习" Me.CommandButton1.Caption = "Start" Me.CommandButton1.SetFocus End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) On Error Resume Next TF = False Documents("练习文章.doc").Close False End Sub Private Sub UserForm_Layout() UserForm1.Top = 0 UserForm1.Left = 160 End Sub

‘---------------------------------------------------------------------------------------------------------

Public StTime As Date, EnTime As Date, Rn As Integer, Sd As Integer, CountText As Integer, YText As Range Public TF As Boolean, Ys As Integer, Temp As Byte Sub MoveFont() Dim Er As Integer On Error Resume Next If TF = False Then Exit Sub CountText = Application.Selection.End If CountText > 0 Then EnTime = Now Er = Rn + CountText - 1 If Er = YText.End - 1 Then MsgBox "对不起,已到文章末,请重新再来!": UserForm1.CommandButton1.Value = True: Exit Sub DoEvents UserForm1.TextBox1 = Mid(YText, Er, 25) UserForm1.TextBox3.Value = Format(CDate(EnTime - StTime), "H:MM:ss") End If WaitTime End Sub Sub WaitTime() If TF = False Then Exit Sub Application.OnTime When:=Now + TimeValue("00:00:02"), Name:="MoveFont" End Sub Sub Starting() UserForm1.Show (0) End Sub Sub MySub() On Error Resume Next UserForm1.Show (0) Call UserForm_Layout UserForm1.CommandButton1.Value = True End Sub Private Sub UserForm_Layout() UserForm1.Top = 0 UserForm1.Left = 160 End Sub

’--------------------------------------------------------------------------------------------------------------

Private Sub Document_Close() On Error Resume Next Application.CommandBars("text").Reset Options.SaveInterval = Temp TF = False Documents("文字游戏.doc").Close False End Sub

Private Sub Document_Open() On Error Resume Next Temp = Options.SaveInterval If Temp <> 0 Then Options.SaveInterval = 0 Set MyControl = Application.CommandBars("text").Controls.Add With MyControl .FaceId = 102 .Caption = "BeginOrEnd" .Visible = True .OnAction = "MySub" End With For i = 1 To Application.CommandBars("text").Controls.Count - 1 Application.CommandBars("text").Controls(i).Visible = False Next UserForm1.Show (0) End Sub

TA的精华主题

TA的得分主题

发表于 2004-8-20 17:22 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2004-8-21 18:52 | 显示全部楼层

我下载后打开只是篇文章

不会用

[em14][em14][em14]

TA的精华主题

TA的得分主题

 楼主| 发表于 2004-8-23 07:24 | 显示全部楼层

下载该文件夹,并确认二个文档在同一文件夹下(打字游戏.doc \练习文章.doc)

请确认你的宏安全级别为低,或者在出现宏对话时选中运行宏。

其次你得运行“打字游戏”文档,出现一个“打字练习”的窗体,点击此窗体中的“START”按钮即可,这样,该窗体中出现文字,在文档光标处按上窗体的文字进行输入,如果需要结束,点"end"(start\end 均可用右键),然后窗体中将出现你练习的结果.

TA的精华主题

TA的得分主题

发表于 2004-8-23 20:19 | 显示全部楼层
又见到版主大作,得赶紧消化,不然就落伍了,谢谢

TA的精华主题

TA的得分主题

发表于 2005-4-21 10:41 | 显示全部楼层

做得真棒!多谢守柔版主的无私分享!

TA的精华主题

TA的得分主题

发表于 2005-4-21 15:54 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
我按照您的办法,也是只出现控件箱,而没有“start”呀?

TA的精华主题

TA的得分主题

发表于 2005-4-22 01:39 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

版主英明,我下载了您上传的附件,可以运行,真的很棒呀!

但是作为新手的我,实在是无法作出您的这份打字程序出来。

守柔版主您能否上传一个完整的制作过程录像呀?(敬请尽量详细一些,包含如何添加控件和代码等等)

我觉得这份录像应该是很多朋友都热切盼望的,特别是对像我这样的新手是大有帮助的。

我提供了详细易懂的具体制作录像的方法,详见http://club.excelhome.net/viewthread.php?tid=94111

敬请好心的守柔版主朋友帮帮我们这些新手!非常感谢!

TA的精华主题

TA的得分主题

发表于 2006-7-16 16:07 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-6-5 04:58 , Processed in 0.035971 second(s), 15 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表