[Vba Excel] Query Refresh

Solved
kilian Posted messages 8675 Registration date   Status Moderator Last intervention   -  
kilian Posted messages 8675 Registration date   Status Moderator Last intervention   -
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

kilian Posted messages 8675 Registration date   Status Moderator Last intervention   1 526
 
Got it :-)

The query update should not happen in the background:
Selection.QueryTable.Refresh BackgroundQuery:=False
4
Canard007 Posted messages 5954 Registration date   Status Contributor 216
 
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
kilian Posted messages 8675 Registration date   Status Moderator Last intervention   1 526
 
Up :-)
0
kilian Posted messages 8675 Registration date   Status Moderator Last intervention   1 526
 
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
Canard007 Posted messages 5954 Registration date   Status Contributor 216
 
And is there no wait style instruction possible in VBA?
--
HI!
0
kilian Posted messages 8675 Registration date   Status Moderator Last intervention   1 526
 
I just tried with this:
http://www.ilook.fsnet.co.uk/vb/vbsleep.htm

The waiting happens but the request only executes at the end, just like before.....
0