VBA xlCalculationManual trips error when called App_WorkbookOpen

jscranton

Well-known Member
Joined
May 30, 2011
Messages
707
I am trying to change the application settings to xlCalculationManual when opening up a workbook. However, this code throws an error if a workbook is already set to xlCalculationManual (Error: Method 'Calculation' of object'_Application' failed). It does not throw the error if the setting is xlCalculationAutomatic

Code:
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)

    Application.Calculation = xlCalculationManual

End Sub

I tried instead to add a condition in another routine but I am getting very strange results. The "Change Settings" macro runs fine except when called by the WorkbookOpen procedure. Then I get a type mismatch error. If it matters, all of this is part of an excel add-in for an end user. :confused::oops:



Code:
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)

    Call changeSettings
End Sub
_____
Sub changeSettings()
 
 If Application.Calculation <> xlCalculationManual Then Application.Calculation = xlCalculationManual
 If Application.CalculateBeforeSave = True Then Application.CalculateBeforeSave = False


End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Solved.

Apparently, you have to change the setting here:

Code:
Private Sub Workbook_Open()
        Set App = Application
	Application.Calculation = xlCalculationManual
	Application.CalculateBeforeSave = False
End Sub

Rather than in the "Private Sub App_WorkbookOpen" module.

I am sure someone can explain why but wanted to close this in case future users had the same issue.
 
Upvote 0

Forum statistics

Threads
1,213,515
Messages
6,114,080
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top