因为程序有多人在用,为了减少个人长时间占用,设置了空闲超时自动退出。刚开始都能正常运行,后来加入了一段记录员工登录和退出时间就出现报错。
thisworkbook下面的代码:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'下面这段斜体字是后面加上去的记录员工退出系统的时间,之前运行正常,加了这段记录退出时间的代码后报错
_ ROWA = Sheet14.Range("CJ" & Rows.Count).End(xlUp).Row
Sheet14.Cells(ROWA, "CL") = Format(Now, "yy年mm月dd日-hh:mm:ss")
_
On Error Resume Next
Application.OnTime EarliestTime:=TimeValue(Runtime), _
Procedure:="计时器", Schedule:=False
On Error GoTo 0
End Sub
Private Sub Workbook_Open()
Call 登陆窗体.隐藏表
登陆窗体.Show '加载登录窗体
Lasttime = Now + TimeValue("20:" & Sheet13.Cells(32, "c") & ":00")
Call 计时器
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Lasttime = Now + TimeValue("20:" & Sheet13.Cells(32, "c") & ":00") '请在“系统设置”页设置好延时时间
End Sub
下面是“计时器”
Public Runtime, Lasttime
Sub 计时器()
If Now >= Lasttime Then
ThisWorkbook.Save
If Application.Windows.Count = 1 Then
Application.Quit
Else
ThisWorkbook.Close True
End If
Exit Sub
End If
Runtime = Lasttime
Application.OnTime Runtime, "计时器"
End Sub
那段记录员工退出系统时间的三行代码没加之前是正常运行的,加了之后就报错了。请各位看一下问题出在哪。