Capture System Idle Time On Worksheet

VJOSHI

New Member
Joined
Sep 16, 2014
Messages
7
Hi,

I have been working on a form to be supplied to my production floor to capture production but also wanted to have a feature where I know how much time a guy spends away from system (Non Productive).

I found a code which gets me very close to what I want but with a headache :crash:. I am unable to figure out how to get the data on a specific sheet instead of immediate window so I can sum it up..

Need you to help me get this output on a sheet instead..


Paste the below code in a module, Open the immediate window and run printidletime1. Every 5 seconds you would see immediate window popping up the idle time.




Code:
<DIR>Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Private Declare Sub GetLastInputInfo Lib "user32" (ByRef plii As LASTINPUTINFO)
Private Declare Function GetTickCount Lib "kernel32" () As Long
Function IdleTime() As Single
Dim a As LASTINPUTINFO
a.cbSize = LenB(a)
GetLastInputInfo a
IdleTime = (GetTickCount - a.dwTime) / 1000
End Function
Sub PrintIdleTime1()
Debug.Print IdleTime
Application.OnTime Now + TimeSerial(0, 0, 5), "PrintIdleTime2"
End Sub
Sub PrintIdleTime2()
Debug.Print IdleTime
Application.OnTime Now + TimeSerial(0, 0, 5), "PrintIdleTime1"
End Sub
</DIR>
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Instead of

Code:
Debug.Print IdleTime

try like this

Code:
Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1) = IdleTime
 
Upvote 0
Hey This works great.. One more thing to bother you about. Is it possible to trigger the macro of this recording action if system is idle for a certain period time. say 2mins as an example. How will the code look like.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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