我有一张SignOff
表,目前运行私有子。我希望将纸张关闭并保存,如果闲置超过5分钟。
我希望结合下面的内容,但似乎无法让它们同时运行。任何帮助都会受到大力赞赏!
Private Sub Worksheet_Change(ByVal Target As Range)
Const PW = "" 'password to be specified
With Target
If .Column = 10 And .Row > 1 And .CountLarge = 1 Then
.Worksheet.Unprotect Password:="" 'password to be specified
If Len(.Value2) > 0 Then
Application.EnableEvents = False
.Offset(, -1) = Now
.Offset(, -2) = "Actioned by " & UserName
Application.EnableEvents = True
End If
.Locked = True
.Worksheet.Protect Password:=""'password to be specified
End If
End With
End Sub
使用以下计时器代码
Const idleTime = 300 'seconds
Dim Start
Sub StartTimer()
Start = Timer
Do While Timer < Start + idleTime
DoEvents
Loop
Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=True
Application.DisplayAlerts = True
End Sub