[Vba Excel] Query Refresh

Solved
Hello,

I have a little issue with a VBA macro.
Actually, it looks like this:
sub macro() Variable declaration Selecting the first cell Refreshing the query Instructions.... end sub


The big problem is that the query refresh only happens at the end of the script.

I'm doing it like this:
Selection.QueryTable.Refresh


I've tried other things like declaring this refresh in a function and calling it in the macro procedure... Or even using a macro that calls in order the refresh macro and then another macro where the rest of the instructions are, but it doesn't change anything, I still have the same effect.

Do you have any idea?

Thanks.....
Configuration: Windows 2000 Excel 2000

6 answers

  1. Moderator
    Got it :-)

    The query update should not happen in the background:
    Selection.QueryTable.Refresh BackgroundQuery:=False
    4
    1. Contributor
      You mean that you trigger the query refresh but no matter when the code continues to run and doesn't wait for the end of this refresh?
      --
      COIN!
      1
      1. Moderator
        Absolutely :-)

        Wherever I place the update, it only executes at the end of the macro.....

        As a result, all the subsequent instructions perform operations in vain....
        0
        1. Contributor
          And is there no wait style instruction possible in VBA?
          --
          HI!
          0