updating multiple MSQueries

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,285
Office Version
  1. 365
Platform
  1. Windows
Sorry, but I just cant work this one out.

I am updating an old workbook which has an MS Query created before Tables were fasionable.

It was updated as part of a macro

VBA Code:
Sheets("Cost Calc").Range("A5").QueryTable.Refresh BackgroundQuery:=False

works fine.

I wanted to add some data so have recreated the MSQueries (and added 2 new ones) and they are now presented as tables.
I have recorded the mouse clicks used to update them but the code it produces shows it has a syntax error.

VBA Code:
Selection.ListObject.QueryTable. BackgroundQuery := FALSE

1. There is a space between QueryTable. & BackgroundQuery
2. It doesn't like the ":" in the ":="

If I change these to remove the syntax error it runs through the code but doesn't update the table.

this is what I have to update the three tables.....

VBA Code:
With Sheets("Cost Calc")
  Range("A4").ListObject.QueryTable.BackgroundQuery = False
  Range("A8").ListObject.QueryTable.BackgroundQuery = False
  Range("A11").ListObject.QueryTable.BackgroundQuery = False
End With

any help would be appreciated.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Worked it out...

VBA Code:
.Range("A4").ListObject.QueryTable.Refresh BackgroundQuery:=False
.Range("A8").ListObject.QueryTable.Refresh BackgroundQuery:=False
.Range("A11").ListObject.QueryTable.Refresh BackgroundQuery:=False


Looks like a bug in the macro recorder and it missed the ".Refresh" completly
 
Upvote 0
Solution

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

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