Written by Allen Wyatt (last updated July 31, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021
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:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13890) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021.
Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!
When reading information from a text file, your macro may need to start reading at a place other than the beginning of ...
Discover MoreNeed to pull a list of words from a range of cells? This tip shows how easy you can perform the task using a macro.
Discover MoreWhen you use macros to create functions, you might want to share those functions with others�"particularly if they ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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 …
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments