the ultimate refresh-all script?

acol

New Member
Joined
Jan 21, 2021
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi all,
Looking for this for a long time, but never found a definite and all-round 'one-button' vba script.
Maybe someone can pull this off and make a lot of people happy with this; unfortunately I'm unable to pull it of myself.
So the question:

I want 1 script that, for the active workbook:
* updates ALL data connections (differents tabs), and ALL pivots (with different data sources) in that workbook.
and if possible doing the refreshings sequential; for running them all at once (as 'refresh all' does), can sometimes resort in errors...
('refresh all' in a pivot only updates all pivots linked to the same data-source, no other ones)

so in short; something like this:
- check for all data connection in the workbook
- refresh the first data connection, wait until its finished, and then refresh all dependent pivots of that connection in the workbook (spread over multiple tabs)
- refresh the second data connection, wait until its finished, and then refresh all dependent pivots of that connection in the workbook (spread over multiple tabs)
- etc. (do this for all subsequent found data connections)

Can this be achieved?
I would very much appreciate having that macro available.

And to all of you; my best wishes for a healthy, peaceful and excel enriching 2023!

Kr
AC
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Does this do the trick? (untested code)

VBA Code:
Sub RefreshAllConPiv()
    Dim wbcConn As WorkbookConnection
    Dim ptPivT As PivotTable
    Dim wsWS As Worksheet
    
    ' refresh each data connection in turn, waiting for it to finish
    For Each wbcConn In ThisWorkbook.Connections
        wbcConn.OLEDBConnection.BackgroundQuery = False
        wbcConn.Refresh
    Next wbcConn
    
    ' refresh all pivot tables
    For Each wsWS In ThisWorkbook.Worksheets
        For Each ptPivT In wsWS.PivotTables
            ptPivT.RefreshTable
        Next ptPivT
    Next wsWS
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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