+ Reply to Thread
Results 1 to 3 of 3

Trigger Macro If System Is Idle for Certain Time.

  1. #1
    Registered User
    Join Date
    09-22-2014
    Location
    India
    MS-Off Ver
    2003
    Posts
    7

    Red face Trigger Macro If System Is Idle for Certain Time.

    Hi,

    I want to know if its possible to auto-run a macro if there was no mouse or keyboard event for say 2mins. I have a code working to record system idle time in total but that gives me endless counts by end of the day as it records every 2 mins.once user logs in to the form.

    I instead want to trigger the macro only when user is not using keyborad or mouse for more than 2 mins.

    Below code: Paste it in a module, Open the immediate window and run printidletime1. Every 2 mins you would see time stamps in "sheet1".


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Trigger Macro If System Is Idle for Certain Time.

    Hi VJOSHI,

    Thank you for introducing me to the 'GetLastInputInfo()' API (Application Programmer Interface) routine which retrieves the time of the last the last input event. Please note that whenever the mouse is moved or a key is pressed, the value is RESET to ZERO.

    The attached file uses the results from one of your previous questions as a baseline. The Idle time is updated in the UserForm and/or the SpreadSheet. A macro is called when the desired Idle Time expires. Original Question Reference: http://www.excelforum.com/excel-prog...user-form.html

    This file is also the solution to a previous unrelated thread: http://www.excelforum.com/excel-prog...idle-time.html

    There are two ways to periodically update data (in a UserForm or in SpreadSheet cells:
    a. Polling. Polling uses a continuous loop that updates data either unconditionally or according to certain conditions.
    The advantages of polling are that it is simple to implement, and relatively easy to debug. The disadvantage of polling is that it hogs computer resources.

    b. Event (driven) (aka Interrupt) Processing. Event Processing updates data when an event occurs, such as the press of a button, or the expiration of an [Interrupt] Timer. The advantage of Event processing is that it uses a minimum of computer resources. The disadvantages of Event processing is that it is an order of magnitude more complicated than Polling, and Event processing can be very difficult to debug if something goes wrong.

    The solution to your original question uses Polling.

    The SpreadSheet Only implementation here is Event Driven. It schedules a macro to run periodically.

    Lewis
    Attached Files Attached Files

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Trigger Macro If System Is Idle for Certain Time.

    Hello VJOSHI,

    The attached workbook uses System Hooks (API) to monitor the keyboard and mouse. If either are moved the timer resets. Once the timer has expired, the workbook will save changes and close.

    You can change the time in the Workbook_Open() event module. Here is the code.
    Please Login or Register  to view this content.
    The red 2 indicates 2 minutes.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel Idle Time Close
    By MarkSSDM in forum Excel General
    Replies: 3
    Last Post: 04-14-2015, 11:23 AM
  2. Capture System Idle Time
    By VJOSHI in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-25-2014, 11:38 AM
  3. Macro to track system's idle time
    By clickrudra in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-02-2013, 01:50 AM
  4. Trigger Macro on cell change by real time data
    By boesingen in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-04-2013, 04:22 PM
  5. Idle time
    By frequent391 in forum Excel General
    Replies: 1
    Last Post: 07-24-2011, 03:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1