+ Reply to Thread
Results 1 to 4 of 4

Run macro if computer is idle

  1. #1
    Registered User
    Join Date
    02-16-2013
    Location
    Romānia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Run macro if computer is idle

    Hi,

    I have a table that should refresh as often as possible (ideally once/hour).
    The problem is that the table is big and it takes time to refresh and this disturbs my work (I'm working in the same file), so I cant't use the "Refresh every x minutes" native function of Excel.

    What I want is to have a macro that tries to refresh the table every hour, but only if there is no activity on the file and if there is activity, to refresh it once Excel is idle for 1 minute (ie, when I go to the bathroom ).
    So, at 12:00 it should check if Excel is in use (I type something or select cells):
    - if Excel is not in use, then it should refresh the table
    - if Excel is in use, then it should wait and check when Excel is idle for 1 minute and then refresh

    Is there a way I can achieve this?
    Thank you.

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Run macro if computer is idle

    http://www.excelforum.com/excel-prog...tain-time.html
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Registered User
    Join Date
    02-16-2013
    Location
    Romānia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Run macro if computer is idle

    Thank you, but if I understand correctly, this code is monitoring if the computer is idle.
    Maybe I was not very clear, I want it to run if Excel is idle (ie, if I'm browsing the web).

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Run macro if computer is idle

    I can think of a way to make this happen.

    The query is probably taking a long time to run since it is a complex query running against a large database. Why not run the query in a separate workbook to get the results. After the query is done have it write a date stamp to a cell on another worksheet.

    Now in the workbook you are working in, do a query against the workbook that runs the query for the date stamp. You can have this refresh every 5 minutes without it being a burden on your work. Use a change event (it should work for a data refresh) on the result and have it notify you when a change to the date stamp has happened. This means that the data has changed since the last time you looked at it.

    Then you can refresh the query for the full data against the workbook. The data there is a "flat file" and should download quickly. You could also tie this in with the change event to run the query automatically.

    Instead of keeping the workbook that queries the database open all the time, you could run it using the windows task manager. This way it won't be open all the time (only when running the query) and it will run in the background and in a separate instance of Excel so it won't interfere with any other Excel workbooks you have opened manually.

    There are several ways to run a macro in another workbook using the task scheduler. The following article is one of them. The way it works is that you fill out the script with the path to the spreadsheet you want to run (target workbook), the name of the spreadsheet you want to run and the macro within that spreadsheet that you want to execute.

    The script shows the path to itself which you can copy and paste into the windows task scheduler. So the task scheduler runs the script (which has an on open macro in it) which then runs the macro in the target workbook.

    Additionally the script writes a status of the result of the run. To see it you can navigate to the script in Excel and open it while holding down the shift key. Holding the shift key will keep the script macro from running.

    http://www.utteraccess.com/wiki/inde...a_Macro_to_Run
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ 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. VBA and Macro to Create Button/Excel Tool that Changes Color with System Idle Time
    By xuiyingsans in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-17-2016, 02:18 AM
  2. VBA and Macro to Create Button/Excel Tool that Changes Color with System Idle Time
    By xuiyingsans in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-17-2016, 12:38 AM
  3. Trigger Macro If System Is Idle for Certain Time.
    By VJOSHI in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2014, 12:42 PM
  4. 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
  5. Replies: 6
    Last Post: 06-28-2013, 08:44 PM
  6. Excel - Auto Timeout on Idle, Warning, Prevent Work until Macro enabled
    By kevin1010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-25-2013, 07:29 AM
  7. Auto Filter on my home computer differs from my work computer.
    By Sbova0226 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-08-2009, 03:04 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