What is wrong with the external data query code?

whr4th

New Member
Joined
Nov 8, 2004
Messages
20
I am trying to cycle through many worksheets and update the query on each one. I cannot use RefreshAll as I think there must be some sort of time constraint on how long each one takes to update. Some of these queries take 5+ minutes.

Here's my code:
Sub Refresh_All()

Application.ScreenUpdating = False

'Cycle through worksheets
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate

ActiveWorksheets.QueryTable.Refresh (False)

Next ws

Worksheets("Main").Activate

Application.ScreenUpdating = True

End Sub

I keep getting a run-time error 424. I have tried several different methods from this board but keep striking out. :oops:

I'm sure it's simple and right in front of my face. Please help!

Thanks in advance.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Just a thought: can you turn calculation to manual, then refresh all?
 
Upvote 0
Nope, tried that and I get a Run Time Error 1004: General ODBC Error.

I think that from reading prior posts, there is a certain length of time between refreshes and if your is still trying to update, it times out.

Other thoughts? I think I just have the verbiage incorrect and I can't figure it out. I even tried the macro recording and tried using:

Range("D9").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

But that didn't work either as I got a Run-time error '1004': Application-defined or object-defined error.
 
Upvote 0
And just to clarify - the error I get is: Run-time error '424': Object required.

I have tried all of the following:
ActiveWorksheets.QueryTables(1).Refresh BackgroundQuery:=False
ActiveWorksheets.QueryTables.Refresh BackgroundQuery:=False
ActiveWorksheets.QueryTables.Refresh
ActiveWorksheets.QueryTable.Refresh ()
ActiveWorksheets.QueryTable.Refresh (False)

And I am sure several others that I can't recall. As I said, I am sure it is something simple but I just can't see it.
 
Upvote 0
Another follow up.

I found this code doing some board searching:

ActiveSheet.QueryTables(1).Refresh False

I tried it and now get a Run-time error '9': Subscript out of range.

Still searching..... :oops:
 
Upvote 0
Updating data from Access during an Excel macro

Did you find any solution? I think I am experiencing exactly the same problem
 
Upvote 0

Forum statistics

Threads
1,214,892
Messages
6,122,112
Members
449,066
Latest member
Andyg666

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