0

I am trying to refresh data in my excel sheet. The problem is I want to refresh it before i do anything else but it does not work that way- data is refreshed only AFTER script ends. For example:

ActiveWorkbook.Connections("Name").OLEDBConnection.CommandText = "SELECT * FROM ...(not important)"
ThisWorkbook.RefreshAll

REST OF THE SCRIPT WHICH USES ^ DATA

So the rest of my scipt always uses old data. When script it shows refreshed data but it looks like it only hapens AFTER everything.

Jorhanc
  • 310
  • 2
  • 13
  • Does this answer your question? [Excel VBA: Screen doesn't refresh during loop](https://stackoverflow.com/questions/40015962/excel-vba-screen-doesnt-refresh-during-loop) – Luuk Nov 02 '20 at 13:54

1 Answers1

1

Please, try inserting this line, before refreshing:

ActiveWorkbook.Connections("Name").OLEDBConnection.BackgroundQuery = False

Otherwise, Excel makes the refreshing in background and let the code to continue, processing what exists...

FaneDuru
  • 38,298
  • 4
  • 19
  • 27