?
Solved

Excel VB Macro - Switch on & Off Calculations

Posted on 2008-09-29
5
Medium Priority
?
712 Views
Last Modified: 2012-05-05
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
Comment
Question by:amacfarl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 50

Accepted Solution

by:
Dave Brett earned 2000 total points
ID: 22595950
Application.Calculation = xlCalculationManual
'at end
Application.Calculation = xlCalculationAutomatic

Cheers

Dave
0
 
LVL 6

Expert Comment

by:dambuster99
ID: 22595958
h there,
try

Application.Calculation = xlCalculationManual

cheers
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22595982
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
 
LVL 2

Expert Comment

by:sal-ee
ID: 22595986
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22595993
oops ... application.EnableEvents = false at the start and application.EnableEvents = true at the end.

Chris
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question