logo
search
VBA & Macro Problems

How to Prevent Background Data Model Refreshes in Excel VBA

Amos GikundaAmos Gikunda Oct 19, 2026 868 views

Question details

The user needs to prevent Excel's Data Model from running background refreshes asynchronously when VBA copies CubeValue formulas to new worksheets, as standard UI settings do not fully stop this behavior.

How to Prevent Background Data Model Refreshes in Excel VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
Executing a VBA macro that duplicates worksheets containing CubeValue formulas linked to a large Data Model, causing asynchronous recalculations and queries.
Observed behavior
CubeValue formulas fail to return immediate final results because Data Model refreshes and workbook calculations continue asynchronously in the background, ignoring basic refresh configurations.
Before you start

Before modifying your macro code, ensure your workbook is saved and create a backup copy to prevent accidental data corruption during asynchronous refresh loops.

Solution 1Recommended

Control Calculation State and Use a Wait Loop in VBA

Manually suspend workbook calculations and use VBA to monitor the specific connection's refresh status, ensuring operations complete before proceeding.

Because Data Models and Cube functions process queries asynchronously, turning off 'Enable Background Refresh' in the Excel user interface is not always sufficient. You must explicitly control the calculation state and use a wait-and-check loop in your code to verify that the connection has finished refreshing before allowing Excel to evaluate the formulas.

1
Disable Automatic Calculation

Open the VBA Editor (ALT + F11), locate your macro, and insert `Application.Calculation = xlCalculationManual` at the beginning of the script to prevent immediate formula evaluation.

2
Trigger the Refresh

Copy your formulas or worksheets as intended within the macro, then execute a refresh on the specific Data Model connection using `ActiveWorkbook.Connections("YourConnectionName").Refresh`.

3
Implement a Checking Loop

Write a `Do While` loop that checks `ActiveWorkbook.Connections("YourConnectionName").OLEDBConnection.Refreshing`. Inside the loop, use `Application.Wait` to pause macro execution momentarily until the property returns False.

4
Restore Automatic Calculation

Once the loop completes (indicating the refresh is finished), insert `Application.Calculation = xlCalculationAutomatic` and `Application.Calculate` to safely evaluate the CubeValue formulas.

Control Calculation State and Use a Wait Loop in VBA
Checking Connection Status: Relying strictly on Application.CalculationState often fails for Data Models. You must check the specific OLEDB connection's 'Refreshing' boolean to guarantee completion.
Free Microsoft Office alternative

Looking for a fast, lightweight alternative for your spreadsheet tasks?

If complex Data Models, asynchronous calculation bugs, and heavy VBA processing in Microsoft Excel are causing bottlenecks, try WPS Office. It provides a lightweight, highly compatible spreadsheet environment that executes standard VBA macros quickly without the heavy overhead of Microsoft's advanced BI tools.

Fully compatible with Microsoft Excel formats (.xlsx, .xls, .xlsm).Supports standard VBA macros and complex spreadsheet automations.Lightweight architecture ensures faster load times and smoother performance.Completely free to download with an intuitive, familiar user interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why do my CubeValue formulas display '#GETTING_DATA' during a VBA macro?

CubeValue formulas retrieve data from the Excel Data Model asynchronously. If a VBA macro copies formulas and finishes execution before the Data Model completes its background query, Excel displays '#GETTING_DATA' until the calculation is finalized.

Does disabling 'Enable Background Refresh' in the UI stop all background queries?

No. Disabling that option primarily stops scheduled or UI-driven background refreshes. Certain VBA operations and formula evaluations tied to the Data Model may still initiate asynchronous data retrieval processes.

Can I use DoEvents in VBA to wait for the Data Model refresh?

While DoEvents yields execution control to the operating system temporarily, it does not reliably halt VBA execution until an OLEDB connection refresh finishes. A loop that explicitly checks the connection's 'Refreshing' property is highly recommended instead.