Hi,
So... I am trying to run some code to effect changes to the spreadsheet with Calculation State set to Manual, then switch it back to Automatic whilst retaining control still within the Macro - allow all the updates to take place and then putout a Msgbox "Done".
The code is something like this...
My query is regarding the WaitForCalculationToFinish routine and the Do While Loop...
As it currently stands - will this work or am I missing something such that I could loop endlessly ?
Am I achieving my objective of retaining control of the macro until all updates are complete ?
Any assistance gratefully received
Jabba
So... I am trying to run some code to effect changes to the spreadsheet with Calculation State set to Manual, then switch it back to Automatic whilst retaining control still within the Macro - allow all the updates to take place and then putout a Msgbox "Done".
The code is something like this...
Code:
Sub Domystuff()
Application.Calculation = xlManual
'
' lots of code here that effects lots of changes to the spreadsheet...
'
Application.Calculation = xlAutomatic
Application.Wait(Now +#0:00:03#) ' Pause briefly to enable Calculation to get started
WaitforCalculationToFinish
End Sub
Private Sub WaitForCalculationToFinish()
Const delayInSeconds = 15
Dim startTime As Double
startTime = Timer
Do While Timer < startTime + delayInSeconds And Application.CalculationState <> xlDone
DoEvents
End If
MsgBox "Done"
End Sub
My query is regarding the WaitForCalculationToFinish routine and the Do While Loop...
As it currently stands - will this work or am I missing something such that I could loop endlessly ?
Am I achieving my objective of retaining control of the macro until all updates are complete ?
Any assistance gratefully received
Jabba