VB如何编写 点击按钮 打开一个文件 延时5秒后输入123 如何编写?

2025-05-22 06:07:02
推荐回答(3个)
回答1:

参考这个:
Private Sub Form_Load()
Dim x
x = Shell("Notepad.exe", vbNormalFocus)
SendKeys "这是一个文本文件的测试程序.", True ' 模拟输入英文字符串
SendKeys "{Enter}{Enter}", True ' 两次回车
waittime (2) ' 延时 2 秒
SendKeys "自动输入文字", True
SendKeys "{Enter}{Enter}", True
waittime (2)
SendKeys "既不是病毒,也不是木马!", True
SendKeys "{Enter}{Enter}", True
waittime (2)
SendKeys "开始退出... 看菜单项{(}F{)}...", True
SendKeys "%", True 'Alt 键激活菜单条
waittime (1)
SendKeys "(F)", True '按字母 "F",选择"文件(F)"菜单
waittime (1)
SendKeys "(X)", True '按字母 "X", 选择"退出(X)"
waittime (2)
SendKeys "(N)", True '弹出一个对话框,询问文件是否存盘,按 "N" 不存盘
End '结束本模拟程序
End Sub
Private Sub waittime(delay As Single)
Dim starttime As Single
starttime = Timer
Do Until (Timer - starttime) > delay
Loop
End Sub

回答2:

问题是解决了, 但是能告诉我 下面一段是什么意思吗。
Private Sub waittime(delay As Single)
Dim starttime As Single
starttime = Timer
Do Until (Timer - starttime) > delay
Loop
End Sub
--------------------------------------------------------------------
这部份的功能是达成你延时5秒再输入。
他的代码中有waittime(2)'就是延时2秒后再处理下面的程序~~

回答3:

我是来凑数的。。