data refresh all worksheets in a workbook using vba

G

Guest

I have set up a Database query and query will get data to populate all
worksheets in a workbook. At the moment I have to go to each worksheet and
press refresh data button to update. Is there a VBA code whereby I could
refresh all worksheets in the workbook.

Thanks
 
K

Ken Wright

Sub RefreshQrys()
For Each wSht In ThisWorkbook.Worksheets
For Each qt In wSht.QueryTables
qt.Refresh
Next
For Each pt In wSht.PivotTables
pt.RefreshTable
Next
Next
End Sub


Works best if none of the queries have the "BackgroundQuery" property set to
true as it ensures that they are refreshed 1 at a time
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top