Help with an Excel Macro

  • Thread starter Thread starter CS
  • Start date Start date
C

CS

I am doing a macro that opens an excel workbook, then refreshes the data
from an external database. I then save and close the excel workbook. When I
look at the macro in the immediate window it appears to work fine, but when
I try to run it I get a message that states something like you are
attempting a command that will interrupt a refresh command do you want to
continue. Yes or cancel.

Not sure what I am doing wrong. Any help would be greatly appreciated. I am
relatively new to using excel.
 
It would help if you post your code. Most likely, when you're debugging, you
are waiting for the refresh to finish before you execute the next line. But
when you're not in debug mode, the line that follows the Refresh command will
execute immediately even if the Refresh command hasn't finish yet. Check the
Refreshing property of the QueryTable object. For example,

Dim q as QueryTable

if q.Refreshing then
'still refreshing
else
'done refreshing
end if

You'll have to put that in a timer or maybe a while loop.
 
One other way is to declare your query table with events and then trap the
AfterRefresh event.

Public WithEvents qt As QueryTable

Private Sub q_AfterRefresh(ByVal Success As Boolean)
'your code here.
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top