Skip to content

[Excel] Recalculate Sheets on Workbook Open (Using VBA)

Add to ThisWorkbook->Workbook code.

Private Sub Workbook_Open()
Dim oSht As Worksheet

Dim xlCalc As XlCalculation

On Error GoTo ErrorHandler

'remember the user's calculation setting before setting it to manual
xlCalc = Application.Calculation
Application.Calculation = xlCalculationManual

For Each oSht In Worksheets
oSht.EnableCalculation = False
oSht.EnableCalculation = True
Next oSht


On Error Resume Next

'restore the user's calculation setting
Application.Calculation = xlCalc

'the ErrorHandler code should only be executed if there is an error
Exit Sub


Debug.Print Err.Number & vbLf & Err.Description

Resume ErrorExit

End Sub