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
Solved

Excel VB Macro - Switch on & Off Calculations

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

861 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