Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 734
  • Last Modified:

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.
0
amacfarl
Asked:
amacfarl
1 Solution
 
DaveCommented:
Application.Calculation = xlCalculationManual
'at end
Application.Calculation = xlCalculationAutomatic

Cheers

Dave
0
 
dambuster99Commented:
h there,
try

Application.Calculation = xlCalculationManual

cheers
0
 
Chris BottomleyCommented:
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
0
 
sal-eeCommented:
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 =)
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

Open in new window

0
 
Chris BottomleyCommented:
oops ... application.EnableEvents = false at the start and application.EnableEvents = true at the end.

Chris
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now