View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ken Wright Ken Wright is offline
external usenet poster
 
Posts: 634
Default data refresh all worksheets in a workbook using vba

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

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 97/00/02/03

----------------------------------------------------------------------------
It's easier to beg forgiveness than ask permission :-)
----------------------------------------------------------------------------

"Sarah W" <Sarah wrote in message
...
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