Track system idle time using VBA

vds1

Well-known Member
Joined
Oct 5, 2011
Messages
1,200
I want to track system idle time (i.e.. There is no use of keyboard or mouse on any applcation) using VBA. Could someone help me on getting this code?
 
I have checked this code but no success, I have a timer code which I want to link with system idle time so that every thie system is idle for 5 or more minute it will start counting the time and once user activity is noted it will pause...
the code is like...
Dim StopTimer As Boolean
Dim Etime As Single
Dim Etime0 As Single
Dim LastEtime As Single
Dim tcount As Single
Private Sub ExitBtn_Change()
If ExitBtn.Value = True Then
StopTimer = True
Sheets("sheet1").Range("b2").Value = ElapsedTime.Text
tcount = 0
Unload Me
End If
End Sub
Private Sub ResetBtn_Change()
If ResetBtn.Value = True Then
StopTimer = True
Etime = 0
Etime0 = 0
LastEtime = 0
tcount = 0
ElapsedTime.Text = "00:00:00"
End If
End Sub
Private Sub StartBtn_Change()
If StartBtn.Value = True Then
StopBtn.Value = False
StopTimer = False
Sheets("sheet1").Range("b2").Value = tcount
Etime = tcount
Etime0 = Timer() - LastEtime
Etime0 = Sheets("sheet1").Range("b2").Value
Do Until StopTimer
Etime = Int((Timer() - Etime0) * 100) / 100
If Etime > LastEtime Then
LastEtime = Etime
ElapsedTime.Text = Format(Etime / 86400, "hh:mm:ss") '& Format(Etime * 100 Mod 100, "00")
DoEvents
End If
Loop
End If
End Sub
Private Sub StopBtn_Change()
If StopBtn.Value = True Then
StartBtn.Value = False
Sheets("sheet1").Range("b2").Value = ElapsedTime.Text
tcount = Sheets("sheet1").Range("b2").Value
StopTimer = True
'Beep
'TextBox1.Value = ElapsedTime.Text
End If
End Sub

where I just want to start and stop timer , can you please help me with this..
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi ,Thanks For code sharing however my requirment is small diffrent.I want system idle time in HH:MM:SS format.LikeIdle start time Idle end time Total idle time(Idle end time-Idle start time)06:10:00 06:15:20 00:15:20Please help on this.Advanced thanks Nil
 
Last edited:
Upvote 0
Hi ALl,

looking for a antidote to the above situation. meaning which can register a activity while user is away..please advise
 
Upvote 0

Forum statistics

Threads
1,215,837
Messages
6,127,187
Members
449,368
Latest member
JayHo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top