Solved

Excel VB Macro - Switch on & Off Calculations

Posted on 2008-09-29
5
693 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 500 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

726 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