Wauvel

Excel like a finance pro.

The functions, VBA, and shortcuts a finance operator actually uses — curated, with CFO examples. Prefer them pre-built? Grab a ready-made model.

← All VBA snippets

Refresh every query and pivot, then wait

Refreshes all data connections and PivotTables and blocks until background queries finish.

Difficulty

Amateur
Workbook

1What it does

Refreshes every data connection, Power Query, and PivotTable in the workbook, then waits for background queries to actually finish before the macro continues — so any code that follows reads fresh data, not stale numbers. A branded status bar shows progress while it works and a tidy message confirms when everything's current.

2The code

Sub RefreshEverything()
    Const BRAND As String = "Wauvel"   ' shown while it works and when it's done
    Application.StatusBar = BRAND & ": refreshing all queries and pivots..."
    ThisWorkbook.RefreshAll
    Application.CalculateUntilAsyncQueriesDone
    Application.StatusBar = False
    MsgBox "Every query and pivot is up to date.", vbInformation, BRAND
End Sub

Paste into the Visual Basic Editor (Alt + F11 → Insert → Module), then run and save as macro-enabled (.xlsm) — or download the workbook: a branded Excel file with this code on a sheet, sample data to run it on, and a step-by-step setup guide.

New to macros? Set up in 5 minutes
  1. 1

    Don't see the Developer tab in the ribbon?

    You don't strictly need it — Alt + F11 opens the editor directly — but it makes running macros easier.
    • Windows: File → Options → Customize Ribbon → tick Developer in the right-hand list → OK.
    • Mac:Excel → Preferences → Ribbon & Toolbar → tick Developer → Save.
  2. 2

    Paste in the code

    Press Alt + F11 to open the Visual Basic editor, then Insert → Moduleand paste the snippet's code into the blank window. Close it with Alt + Q.
  3. 3

    Run it

    Press Alt + F8, pick the macro's name, and click Run — that's it. (Pasted a custom function instead? Just type it into a cell like any built-in: =GrossMargin(B2, B3).)
  4. 4

    Keep the macro — save as .xlsm

    File → Save As → Excel Macro-Enabled Workbook (.xlsm). A plain .xlsx silently drops the code when you save.
  5. 5

    Macros blocked?

    Click Enable Content on the yellow bar. If you downloaded the file, you may first need to right-click it → Properties → tick Unblock → OK, then reopen.

Heads up: macros can't be undone with Ctrl + Z — save a copy before running one that changes your workbook.

3When you use it

  • Update a dashboard built on Power Query before exporting.
  • Make a 'refresh then save/email' routine reliable.
  • Force a full recalc of connected data on open.

4See it in action

A simulation — press Run to perform what the macro does to a sample workbook.

Last refreshed: 3 days ago
Revenue$80,000
Expenses$58,000

5Pitfalls

Code after RefreshAll runs before data lands.

Fix: Keep CalculateUntilAsyncQueriesDone — it blocks until background refreshes finish.

A connection prompts for credentials.

Fix: Save credentials in the connection, or refresh interactively the first time.

6No-code alternatives

  • Data → Refresh All Ctrl + Alt + F5 refreshes everything manually.
  • Refresh on open Set the connection to refresh when the file opens (no macro).

Rather not write macros? Wauvel's free tools generate branded, formula-driven Excel for you — no VBA required.

Learn the moves here — or let Wauvel run them on your numbers.

Get my free report →