title: Wait until ActiveWorkbook.RefreshAll finishes - VBA
body: <p>I have a sub that calls on <strong>ActiveWorkbook.RefreshAll</strong> to bring new data in from an XML source, and then performs multiple modifications to it. The problem is that not enough time is given for the RefreshAll command to finish, so the following subs and functions end up not executing correctly, which result in repeated rows not being correctly erased.</p>
  
  <p>I have tried using <strong>Application.Wait</strong> and the <strong>Sleep</strong> function, but they seem to pause the refresh process too. I simply want the rest of the code to wait until the refresh process finishes before executing the rest of the code.</p>
  
  <p>Any ideas on how to implement this? Right now I was only able to fix it by not calling on RefreshAll, which gives me the idea of implementing a second flow to be executed afterwards, but that's not a good workaround.</p>
  
  <p>Please let me know if any of this wasn't clear. Thanks</p>
  
  <p><strong>EDIT</strong>
  So I tried a few suggestions from the posts below, and this is what I was able to come up with.
  Doing a "record macro" and then UNCHECKING the "Enable background refresh" in the table properties did not result in anything. I did a refresh as well afterwards. This was the result of the recorded macro:</p>
  
  <pre><code>With ActiveWorkbook.Connections("XMLTable")
          .Name = "XMLTable"
          .Description = ""
  End With
  ActiveWorkbook.Connections("XMLTable").refresh
  </code></pre>
  
  <p>The class <strong>ActiveWorkbook.Connections</strong> does NOT have a <strong>BackgroundQuery</strong> option so that I can set it to False. Any ideas?</p>
  
  <p>Just to be clear. This is an XML file hosted on a website which Excel goes and imports into a table. I then call that data into a pivot and other things. The goal here is to allow the import process from the website to the table to finish BEFORE executing any other commands.
  Thanks</p>
  
  <p><strong>EDIT2:</strong>
  After a little more research, I have found this page: <a href="http://www.mrexcel.com/forum/excel-questions/564959-execute-code-after-data-connection-refresh-finished.html" rel="noreferrer">http://www.mrexcel.com/forum/excel-questions/564959-execute-code-after-data-connection-refresh-finished.html</a>
  It appears that an XML type of connection does not have a <strong>BackgroundQuery</strong> boolean. That option is only available for ODBC and OLEDB connections, which are types xlConnectionTypeODBC and xlConnectionTypeOLEDB, respectively. The XML connection I am using is of type xlConnectionTypeXMLMAP which does not have a <strong>BackgroundQuery</strong> option.
  Does anyone have any idea on where to go from here? The only solution I have in mind right now is to make two seperate macro buttons on the excel sheet, one for refreshing and one for data modification, but I'd rather keep that option to the very last.</p>