title: Application.CalculateUntilAsyncQueriesDone Crashes Excel
body: <p>I have a OLAP Data Model that is published on the Power-BI Services. I built a report using <code>CUBE</code> formulas. I need to do a bit of Hiding and Showing Columns based on the <code>CUBEVALUE</code> results. And I need to print PDF's for a whole bunch of slicer selections. Naturally, I need my VBA Sub to wait until all the <code>CUBE</code> formulas finish refreshing.</p>
  <p>I know that the <code>Application.CalculateUntilAsyncQueriesDone</code> method will let me wait until the refresh completes. However, in Excel 2016, it just seems to crash excel. It just waits indefinitely.</p>
  <p>Excel Version: <strong>Microsoft Excel for Microsoft 365 MSO (16.0.13001.20254) 64-bit</strong></p>
  <p>I faced the same issue with Power-Query Queries, but setting the <code>BackgroundQuery</code> property of all the Queries to <code>FALSE</code> before calling <code>Application.CalculateUntilAsyncQueriesDone</code> solved the crashing problem. Unfortunately, the <code>BackgroundQuery</code> property cannot be set to <code>FALSE</code> for an OLAP Data Connection.</p>
  <p>The following technique did not work either:</p>
  <pre><code>Do Until Application.CalculationState = xlDone
  Loop
  </code></pre>
  <p>The refresh starts a bit late, and during that time the <code>Application.CalculationState</code> is <code>xlDone</code> and the code just does not wait for the refresh to even start. If I use the <code>Application.Wait</code> method, the Query also waits to refresh.</p>
  <p>Is this just on my computer? Or, are all of you facing issues with <code>Application.CalculateUntilAsyncQueriesDone</code>?
  How have you worked around this issue?</p>