VBA to Refresh Connections

happyhungarian

Board Regular
Joined
Jul 19, 2011
Messages
205
Hi, I have code that automatically does a RefreshAll when a worksheet is activated. My issue though is that I need the refreshes to happen in a certain order since pivotables are based off of connection refreshes. I would need all connections to be refreshed first and then all pivotables to be refreshed.

Thanks!

Jesse
 

happyhungarian

Board Regular
Joined
Jul 19, 2011
Messages
205
I've tried the following but it's still not working


Private Sub Worksheet_Activate()


Call RefreshConsolidation


DoEvents


Call AllWorkbookPivots


End Sub








The RefreshConsolidation code is:

Sub RefreshConsolidation()


ActiveWorkbook.Connections("Query - Append2").Refresh

End Sub
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
5,995
What isn't working? Do you get any errors? What type of connections are they - ODBC, OLEDB, WORKSHEET, or another type?
 

happyhungarian

Board Regular
Joined
Jul 19, 2011
Messages
205
I thought the DoEvents would pause the macro long enough for the ActiveWorkbook.Connections("Query - Append2").Refresh to finish before the PivotTables refreshed but it's not. There are no errors. So the Pivots refresh off of the old data on the Append2 rather than the new. The Append2 query is simply an append operation of multiple tables on my worksheet that I have turned into Connections. So everything is housed within the workbook. I'm wondering if I need to add a backgroundquery=false operation somewhere in the code???
 

Forum statistics

Threads
1,081,679
Messages
5,360,482
Members
400,588
Latest member
SpannersWatson

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top