Check if workbook is waiting to calculate

S

sime

Hi listers

Is there a way to programatically check whether a workbook is waiting
to be refreshed? I am looking for something like:

Thisworkbook.NeedsCalculating

I am forcing a calculation of a worksheet with the following code:

***code start***
With ThisWorkbook.Worksheets("MyReport")

.EnableCalculation = True
ThisWorkbook.RefreshAll
.EnableCalculation = False

End With
***code end***

....however, if I click the sheet while the calculation is occuring, the
calculation cancels and the code continues to run without having
refreshed properly. How can I check if the calculation has completed?

Hope someone can help
Regards
Simon Hobbs
 
J

Jim Cone

Simon,

Untested but it ought to work...
Application.StatusBar = "Starting Refresh" 'new line
With ThisWorkbook.Worksheets("MyReport")
.EnableCalculation = True
ThisWorkbook.RefreshAll
.EnableCalculation = False
End With
Application.StatusBar = "Refresh Complete" 'new line
'other code
Application.StatusBar = False 'new line

Regards,
Jim Cone
San Francisco, USA
 
S

sime

Hi Jim
I need to be a bit more specific. Here's a modification of the code
with pseudo-code to represent what I want to do.

With ThisWorkbook.Worksheets("MyRep­ort")

.EnableCalculation = True
ThisWorkbook.RefreshAll
While ThisWorkbook.NeedsRefreshing = True
Msgbox "Please wait for the report to refresh."
ThisWorkbook.RefreshAll
Wend
.EnableCalculation = False

End With


That is, at the point where the workbook has supposedly refreshed, I
need to determine if it actually has. If it hasn't, I need to take
measures to enforce the calculation.

Regards
Simon
 

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

Top