Updating a Web Query Based on a Schedule

Written by Allen Wyatt (last updated July 31, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


1

Robert has successfully made a data connection to a website through a web query. He has the web query update, automatically, every two minutes. However, the website to which he's connected is only "live" during certain hours. Robert wonders if there is a way to instruct the web query to update every two minutes, but only during a schedule that he establishes.

Not knowing the exact manner in which Robert is triggering his web query, only some general guidance can be given. The trick is going to be to figure a way to turn on the web query and a separate way to turn it off. The easiest way to handle this is to write two routines, which I'll call TurnQueryOn and TurnQueryOff. You could then use the OnTime method to specify when you want the query turned on. Here's an example that runs the proper routine at 6:00 am:

Application.OnTime TimeValue("06:00:00"), "TurnQueryOn"

You could, right after scheduling when to turn the query on, schedule when to turn it off:

Application.OnTime TimeValue("15:00:00"), "TurnQueryOff"

This code runs the TurnQueryOff routine at 3:00 pm. In these code lines, of course, the trick will be to develop the TurnQueryOn and TurnQueryOff macros and make sure they actually do what they are supposed to do.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13890) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Table Borders not Stored in AutoText

Many people create tables and store those tables in AutoText entries for later use. If the formatting of those tables ...

Discover More

Hiding a Huge Number of Rows

Need to hide a large number of rows? It's easy to do if you combine a few keyboard shortcuts. Here are several techniques ...

Discover More

Evaluating Formulas

Need a bit of help in figuring out how Excel is evaluating a particular formula? It's easy to figure out if you use the ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Calculating Time Differences between Two Machines

Want to know how much of a time difference there is between your machine and a different machine? This tip provides some ...

Discover More

Develop Macros in Their Own Workbook

If you develop macros and edit them quite a bit, you may be running the risk of causing problems with the macros or with ...

Discover More

Changing Macro Cell References Based on Edits

Place a cell reference in a macro, modify the structure of your worksheet, and you may soon find that the cell reference ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 5?

2021-07-31 14:36:37

Philip

I’d be interested in more details about how to set umpteen web query, and what the (table / formatting) requirements on the web side of the connections would be …


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.