Reputation: 124696
I want to take an action in an Excel workbook macro after a period of inactivity (hide/protect some worksheets). What is the best/simplest way to achieve this?
Í'm assuming I'll use Application.OnTime
to periodically check if the user has been active. But what events should I handle to see if the user was "active" (i.e. has does something - anything - with the workbook)?
Clarification: I want to detect all activity, not just changes. I.e. including mouse clicks, selecting, copying, navigating with the keyboard, changing worksheets, ...
I'm assuming that when a UI event happens that represents user activity, I will set a variable thus:
LastActivityTime = Now
and the macro run by Application.OnTime
will check this variable to see if the user has been active recently. Which events (other than SheetChange
) would I need to handle to set this variable? I had kind of hoped there would be KeyUp
and MouseUp
events, these two would probably have been enough.
Update: I have implemented this by handling Workbook_SheetActivate
, Workbook_SheetSelectionChange
and Workbook_WindowActivate
. Realistically this is probably enough.
Upvotes: 2
Views: 3263
Reputation: 124696
I have implemented this by handling Workbook_SheetActivate, Workbook_SheetSelectionChange and Workbook_WindowActivate. Realistically this is probably enough.
Upvotes: 2
Reputation: 78155
I can only see two solutions -- either handle evary single event the Application object has or use GetLastInputInfo function.
Upvotes: 2
Reputation: 21450
One simple way is to compare the content of the workbook with that of the last time you check. I believe combining this with Application.OnTime will solve your concern.
Upvotes: 0