+ Reply to Thread
Results 1 to 2 of 2

Set schedule for query to update automatically at a specific time in Excel

  1. #1
    Registered User
    Join Date
    06-26-2015
    Location
    Đan Mạch
    MS-Off Ver
    2010
    Posts
    21

    Set schedule for query to update automatically at a specific time in Excel

    Hi guys

    I have some queries in Excel, where they will go to a database, take the data out and update in my Excel file. Normally, I have click "Refresh All" under tab "Data" in Excel to run those queries. However, I wan to set a specific time for them to run automatically. That means I open my laptop, I open the Excel file then I leave it there and the queries will run automatically at a specific time that is set before.

    How can I do that?

    Thank guys.

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

    Re: Set schedule for query to update automatically at a specific time in Excel

    Check out the link below.

    Download the template script and Open it. Ignore the instructions in the dialog box for the moment. Just OK it. In cell B9, type in the path to where the excel executable exists for your OS and version of Excel. The one in the script is of Excel 2013. Close and save the template. You are now set up to use this template to execute code in any workbook.

    To run a specific report:

    Make a copy of the script and rename it with a descriptive name like "Run Report XYZ"

    Open the copy and fill in the path name to the report you want to run (e.g. \\ServerName\Pathanme), the report you want to run (e.g. Report XYZ.xlsm) and the Macro in that report that you want to run. I usually name the macro I want to run, Executive, and it normally calls other macros in the workbook to refresh data, set pivot table filters or whatever.

    Then open notepad and copy in the contents of cell B11. This string will be used in the windows task scheduler. You can close and save the script file at this point.

    I suggest you do a web search on how to use the windows task scheduler. Here is a good one.
    http://www.howtogeek.com/123393/how-...ask-scheduler/

    Just remember you’ll want to run a program as an action.

    How the system works is that you use the task scheduler to set up a schedule when to run the report. When you get to the part "run a program," copy in the contents of cell B11. When you click to move on, you will get a message about it having an argument. OK this dialog box.

    Optional: before finishing the task, check the box to open the Properties. One of the options is to run the task whether the user is logged in or not. If you select this option, you can leave your workstation logged off, but you will have to provide a current password. So when your password changes, you'll have to go back in and reset it.

    If you plan on staying logged in and lock your workstation, you do not have to do this. Power failures happen or IT runs an update and computers reboot. You know best about the environment in which you work.

    How the system works is that the windows task manager opens the script file. The script file has an on open macro that opens the target report and runs the macro you specify. It also records the result of the run in cell B6.

    When you initially open the script to fill in the data, this macro puts up the dialog box telling you what to do and bypasses the rest of the code. After the three lines are filled in, then opening the macro runs the report automatically. If you want to check the status of the last run or for some reason alter the script, open Excel and navigate to the script in Excel – hold down the SHIFT key while opening it and this will disable the macro.

    One of the advantages of the two-step (scheduler runs the script, script runs the report) is that the report would otherwise have to be designed to have an on open, run a macro event which makes it more cumbersome to work with manually.

    Also the scripts allow you to produce a large number of reports on an “industrial” scale.

    There are some caveats: both the script location and the report location must be in a trusted location. Look under File -> Options -> Trust Center.

    I have all my scripts in a script directory and all my reports in a subdirectories under a Reports directory.

    Also the windows task manager is dumb when it comes to your computer setup. It doesn’t know where Excel lives, for example, which is why you have to tell it that when you set up the template.

    The task manager is unaware of drive mappings, so it usually safer to use complete path names. One exception is C: - everybody has one of those and every computer knows where it is.

    Other restrictions are explained in the article. If you have any questions on how to use the system, just ask.

    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. How to Schedule Outlook Macro to run daily at specific time
    By spriyatam in forum Outlook Formatting & Functions
    Replies: 7
    Last Post: 11-16-2017, 06:05 PM
  2. Replies: 1
    Last Post: 10-19-2015, 11:33 AM
  3. How to send excel file automatically through outlook on specific time daily.
    By ashok155 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-25-2014, 09:08 AM
  4. to automatically email an excel sheet at specific time every day
    By athira11217 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-26-2013, 02:50 AM
  5. Schedule Macro at specific day & time?
    By jasonfish11 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-23-2012, 03:11 PM
  6. Replies: 0
    Last Post: 03-20-2006, 03:48 PM
  7. How to automatically update the date any time the Excel is openned
    By DORI in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-21-2005, 01:10 AM

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