Angus
asked on
Excel VB Macro - Switch on & Off Calculations
Hi,
I have written a VB macro that is very lengthy and executes a number of calculations.
If the macro is run and the Excel Option "Calculation Options" is set to "Automatic" - the macro takes ages. So it needs to be set to "Manual".
Is there any way of doing this directly in the VB script. This prevents idiots running it with it on.
I am using Excel 2007
Cheers
A.
I have written a VB macro that is very lengthy and executes a number of calculations.
If the macro is run and the Excel Option "Calculation Options" is set to "Automatic" - the macro takes ages. So it needs to be set to "Manual".
Is there any way of doing this directly in the VB script. This prevents idiots running it with it on.
I am using Excel 2007
Cheers
A.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The other consideration if you have event handlers is to set application.EnableEvents before data is changed and back to true afterwards ... or at the start of your routine and the end if applicable, (as is oftern the case).
Chris
Chris
The code attached shows how you can switch calculation into manual, run some code, then put it back to how it was.
Hope this helps =)
Hope this helps =)
Sub GoToManual()
Dim xlCalc As XlCalculation
xlCalc = Application.Calculation
Application.Calculation = xlCalculationManual
On Error GoTo CalcBack
'YOUR CODE
Application.Calculation = xlCalc
Exit Sub
CalcBack:
Application.Calculation = xlCalc
End Sub
oops ... application.EnableEvents = false at the start and application.EnableEvents = true at the end.
Chris
Chris
try
Application.Calculation = xlCalculationManual
cheers