2

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.

shruti1810
  • 3,920
  • 2
  • 16
  • 28
Joe
  • 122,218
  • 32
  • 205
  • 338

3 Answers3

2

I have implemented this by handling Workbook_SheetActivate, Workbook_SheetSelectionChange and Workbook_WindowActivate. Realistically this is probably enough.

Joe
  • 122,218
  • 32
  • 205
  • 338
2

I can only see two solutions -- either handle evary single event the Application object has or use GetLastInputInfo function.

GSerg
  • 76,472
  • 17
  • 159
  • 346
  • GetLastInputInfo sounds promising but seems to be related to the user session rather than an application. I am only interested in user activity related to my Excel workbook - or the Excel process would do. – Joe Oct 04 '08 at 14:20
0

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.

Martin08
  • 20,990
  • 22
  • 84
  • 93
  • Thanks, but I want to detect activity that doesn't change the workbook too. I've added some clarification to my question. – Joe Oct 04 '08 at 14:08