Refresh queries after a certain time

Mahmoud451

New Member
Joined
Jan 24, 2023
Messages
1
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I tried to use the following macro to refresh queries as the following:
refresh query 1 after 1 minutes
refresh query 2 after 2 minutes
refresh query 3 after 3 minutes
refresh query 4 after 4 minutes
refresh query 5 after 5 minutes
I got error in this line:
ThisWorkbook.Queries("q1").Refresh
please help
VBA Code:
Sub RefreshQueries()
   For i = 1 To 5
       Application.OnTime Now + TimeValue("0:" & i & ":0"), "RefreshQuery" & i
   Next i
End Sub
Sub RefreshQuery1()
   'Refresh code for query 1
   ThisWorkbook.Queries("q1").Refresh
End Sub
Sub RefreshQuery2()
   'Refresh code for query 2
   ThisWorkbook.Queries("q2").Refresh
End Sub
Sub RefreshQuery3()
   'Refresh code for query 3
   ThisWorkbook.Queries("q3").Refresh
End Sub
Sub RefreshQuery4()
   'Refresh code for query 4
   ThisWorkbook.Queries("q4").Refresh
End Sub
Sub RefreshQuery5()
   'Refresh code for query 5
   ThisWorkbook.Queries("q5").Refresh
End Sub
 
Last edited by a moderator:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Welcome to the MrExcel Message Board! :)

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,213,507
Messages
6,114,029
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top