LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Refreshing MS Query and Excel Pivot Tables using VBA

Sounds good. One question: What menu paths do I use to set the Querytable's
BackgroundQuery to False?

Cheers

"hoppermr" wrote:

I am trying to run a MS Query query in Excel and refreshing a pivot table
afterwards that feeds off the query using VBA. The query dumps the data into
a separate data sheet in Excel. The pivot table reads the Excel sheet (and
is not linked to MS Query directly).

Problem is that the query takes a while to run. The VBA code doesn't wait
for the query to finish before it continues to the next line and refreshes
the pivot tables. The result is that the pivot tables re-refresh but not
based on the latest data.

What I need is code that halts the execution of the VBA until all queries
have run (ie the Query application has closed). Are there other solutions
out there?

Code so far is below:-

Dim wsSheet As Worksheet
Dim qt As QueryTable
Dim pvt As PivotTable

'To update all query extracts in Workbook
For Each wsSheet In Worksheets
For Each qt In wsSheet.QueryTables
qt.Refresh
Next
Next wsSheet

'To update all pivot tables across all worksheets
For Each wsSheet In Worksheets
For Each pvt in wsSheet
pvt.Refresh
Next pvt
Next wsSheet

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Refreshing Pivot Tables hnyb1 Excel Discussion (Misc queries) 1 September 13th 07 01:21 PM
When refreshing pivot tables my pivot table chart type changes hannah220507 Excel Discussion (Misc queries) 1 May 22nd 07 02:57 PM
Refreshing Query Tables Tom Ogilvy Excel Programming 2 August 26th 04 05:35 PM
Refreshing Query Tables FSt1 Excel Programming 0 August 26th 04 03:16 PM
Refreshing Pivot Tables QUery Ron McCormick[_2_] Excel Programming 1 December 3rd 03 06:31 PM


All times are GMT +1. The time now is 05:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"