因为程序有多人在用,为了减少个人长时间占用,设置了空闲退出。刚开始都能正常运行,后来加入了一段记录员工登录和退出时间就出现报错。thisworkbook下面的代码:Private Sub Workbook_BeforeClose(Cancel As Boolean)'****这一段记录退出程序时间和在线时长是后来加上去的,加上去就报错,删除就正常 ROWAAA = Sheet14.Range("CJ" & Rows.Count).End(xlUp).Row Sheet14.Cells(ROWAAA, "CL") = Format(Now(), "yyyy年mm月dd日-hh:mm:ss") '记录退出时间 Sheet14.Cells(ROWAAA, "CM") = "=Time(Mid(CL" & ROWAAA & ", 13, 2), Mid(CL" & ROWAAA & ", 16, 2), Mid(CL" & ROWAAA & ", 19, 2)) - Time(Mid(CK" & ROWAAA & ", 13, 2), Mid(CK" & ROWAAA & ", 16, 2), Mid(CK" & ROWAAA & ", 19, 2))" '记录在线时长'******************************************************************************** On Error Resume Next Application.OnTime EarliestTime:=TimeValue(Runtime), _ Procedure:="计时器", Schedule:=False On Error GoTo 0End SubPrivate Sub Workbook_Open()Call 登陆窗口.隐藏表登陆窗口.Show '加载登录窗体Lasttime = Now + TimeValue("00:" & Format(Sheet13.Cells(32, "c"), "00") & ":00")Call 计时器End SubPrivate Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Lasttime = Now + TimeValue("00:" & Format(Sheet13.Cells(32, "c"), "00") & ":00") '请在“系统设置”页C32单元格设置好延时时间End Sub计时器模块:Public Runtime, LasttimeSub 计时器() 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
这句代码中,建议你把 Now() 后面的括号去掉再试试看。