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.

1

1 Answer 1

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...

Sign up to request clarification or add additional context in comments.

2 Comments

It fixed the problem. Thanks for the solution.
@Jorhanc: Glad I could help!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.