您好我正在寻找在用户处于非活动状态的指定时间后关闭Excel的代码。我有这个问题的在线代码,但它与我的工作簿中的其他宏无法正常运行。我需要可以与其他宏一起运行的代码,并在用户不活动后关闭。任何帮助将不胜感激!
答案 0 :(得分:0)
在每个宏的末尾为不活动计数器调用宏。使用在每个宏开头传递0的全局变量退出不活动计数器宏。仅使用键盘不活动控件的示例代码:
Public br As Integer
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Byte) As Integer
Sub brea()
br = 0
'do stuff here
Call test
End Sub
Sub test()
br = 1
Dim t As Integer
t = 0
While t < 15
t = t + 1
Sleep (1000)
For i = 0 To 255
ret = GetAsyncKeyState(i)
If ret <> 0 Then t = 0
Next
Application.StatusBar = t
If br = 0 Then GoTo Ends
DoEvents
Wend
Application.Quit
Ends:
End Sub