excel - 在 Excel 中手动输入超时
问题描述
我希望用户将数据输入到 Excel 单元格中,但如果输入但未在给定时间内完成,我想在该超时时停止输入,将在此之前输入的内容输入到单元格中。
更新
我现在尝试了下面的代码,但这不起作用。它不会关闭表单或超时。
Sub Button1_Click()
Dim PauseTime, StartTime
On Error Resume Next
UserForm1.Show
' Set duration in seconds
PauseTime = 5
' Set start time
StartTime = Timer
Do While Timer < StartTime + PauseTime
DoEvents ' Yield to other processes
Loop
ActiveCell.Value = UserForm1.TextBox1.Value
Unload UserForm1 ' close the form
End Sub
解决方案
如果你想为此使用用户表单和文本框,你可以这样做:
Private Sub UserForm_Activate()
Dim PauseTime, StartTime
PauseTime = 5 ' Set duration in seconds
StartTime = Timer ' Set start time
Do While Timer < StartTime + PauseTime
DoEvents ' Yield to other processes
Loop
ActiveCell.Value = TextBox1.Value ' set the active cell's value to what is in the textbox
End ' close the form and end the program
End Sub
我不建议使用这种类型的 GUI,因为它会使用户感到困惑。
推荐阅读
- c# - C# 如何知道如何正确修改命名空间以使其工作?
- c++ - R 4.0.3 内联编译在基于 math.h 的 macos 11.0 上失败
- android - Android 构建不起作用(在模块中发现重复的类 com.google.android.gms.internal.measurement.zzbt)
- entity-framework-core - 使用 Entity Framework Core 将成员添加到虚拟集合
- sql - 为redshift中的同一行元素创建具有不同组名的自定义列
- prepared-statement - H2 where 子句中的多个 case 语句
- ruby-on-rails - 如何从选择框列表中禁用 1 项
- airflow - 气流 xcom 作业是否被隔离?
- mysql - 在 Prestashop 中导出废弃购物车的 SQL 请求
- reactjs - React Hook useCallback 缺少依赖项:'params' 和 'posts'。您还可以进行功能更新 'setPosts(p => ...)