Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set application calculation back as to defined by user in Excel VBA?

I have a rather large workbook, and some users prefer to have automatic calculation on, while others prefer having it off.

Some macros that interact with the sheets are attatched to the workbook. To speed up my VBA code, I set

Application.Calculation = xlManual

In the beginning of each workbook.

My question is, how do I revert it back to the way it was in the end of macro?

Right now i'm using

Application.Calculation = xlAutomatic

but that overrides the users choice. It's pretty annoying having to change it back to manual every time the macro has run. (Or the other way around, if leaving it at manual.)

like image 485
johs32 Avatar asked Nov 29 '17 04:11

johs32


People also ask

How do I force a calculation in Excel VBA?

Open the Visual Basic editor (Developer > Visual Basic). Double-click on Sheet1 and paste the code above, i.e. the full code of “Public Sub ForceFullCalculation()”. In the “Assign Macro” dialog, create a new click event handler, or select the method “Sheet1. ForceFullCalculation”.

What does .calculate do in VBA?

Calculate Worksheet Method in VBA is used to calculate all open workbooks or a specific worksheet in a workbook or a specified range in a worksheet.

How do I turn off auto calculate in Excel?

To turn off automatic recalculation and recalculate open workbooks only when you explicitly do so (by pressing F9), in the Calculation options section, under Workbook Calculation, click Manual. Note: When you click Manual, Excel automatically selects the Recalculate workbook before saving check box.


1 Answers

Store the setting before starting, then restore when finished:

Sub calctest()
Dim calcsetting As Integer

    calcsetting = Application.Calculation
    ' Put code here
    Application.Calculation = calcsetting
End Sub
like image 162
Carol Avatar answered Oct 23 '22 05:10

Carol