VBA code to check inactivity on a sheet and display an alert

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I have been doing some digging for a while now and I have come across cool stuffs concerning what I want to achieve.

The only setback is that they are scattered all over in bits.

So I came across this code from @Tom Urtis which tacks the movement of the mouse.

Code:
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
 
Sub PositionXY()
Dim lngCurPos As POINTAPI
Do
GetCursorPos lngCurPos
Range("A1").Value = "X: " & lngCurPos.x & " Y: " & lngCurPos.y
DoEvents
Loop
End Sub

I want to display an alert when there is inactivity in the system for a given duration.

**I will use this to prompt user to login.
**If the alert is on already, I don’t want to pop it again(as that might cause some form of conflict)

Each time there is mouse movement, I want to reset the timer.

When I leave the active workbook to any other window, I want to show the alert (in this case an input box to accept user password) immediately.

I have also come across amazing workarounds from @Jaafar Tribak and the likes:

But I am finding it tougher to rightfully connect the dots.

I will be more than happy if someone can help me out for it.

Thanks in advance
Kelly Mort
 
Hi @Jaafar Tribak I just tried the Window_Deactivate Event and I think I only need what your code is doing so far.

Thanks once again.
Have a great time.
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,215,059
Messages
6,122,913
Members
449,093
Latest member
dbomb1414

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