如何检测 Excel 工作簿中的用户不活动

发布于 2024-07-07 19:40:53 字数 683 浏览 6 评论 0原文

我想在一段时间不活动后在 Excel 工作簿宏中执行操作(隐藏/保护某些工作表)。 实现这一目标的最佳/最简单方法是什么?

假设我将使用 Application.OnTime 定期检查用户是否处于活动状态。 但是我应该处理哪些事件来查看用户是否处于“活动”状态(即对工作簿执行了某些操作)?

澄清:我想检测所有活动,而不仅仅是变化。 即包括鼠标单击、选择、复制、使用键盘导航、更改工作表...

我假设当发生代表用户活动的 UI 事件时,我将设置一个变量:

LastActivityTime = Now

以及由 运行的宏Application.OnTime 将检查此变量以查看用户最近是否处于活动状态。 我需要处理哪些事件(SheetChange 除外)来设置此变量? 我本来希望有 KeyUpMouseUp 事件,这两个可能就足够了。

更新:我通过处理 Workbook_SheetActivateWorkbook_SheetSelectionChangeWorkbook_WindowActivate 实现了这一点。 实际上这可能就足够了。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟凡古楼 2024-07-14 19:40:53

我只能看到两种解决方案 - 要么处理 Application 对象具有的每个单一事件,要么使用 GetLastInputInfo 函数。

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

墨小墨 2024-07-14 19:40:53

我通过处理 Workbook_SheetActivate、Workbook_SheetSelectionChange 和 Workbook_WindowActivate 来实现这一点。 实际上这可能就足够了。

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

暖风昔人 2024-07-14 19:40:53

一种简单的方法是将工作簿的内容与上次检查的内容进行比较。 我相信将此与 Application.OnTime 结合起来会解决您的担忧。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文