View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Prevent automatic calculation for workbook being opened

Maybe you can try this.

Open excel
create a new workbook--so you can change calculation to manual.
Then open your addin.

Do you have the same problem?

I'm guessing that calculation is set to automatic. When the addin opens, the
calculation occurs _before_ your code is run (that's the way excel works). Then
your code toggles the calculation setting, does some work and toggles the
calculation mode--which causes the workbook to be recalculated a second time.

The only way I know to stop it is to make sure calculation is set to manual,
then open your addin.

You could do it manually or you could have another workbook that opens, changes
calculation to manual, opens your addin, and closes itself. Kind of helper
workbook.



Sergiy wrote:

Dear Colleagues,

Please advise with the subject, details are below.

I am getting exported data to excel and this data is in text format
which I am processing to get the values. The macro to process it is
located inside of add-in and it intercepts Application.WorkBookOpen
Event. The point is that excel is calculating twice, before my macro
runs and after. How I can prevent excel from double work? I have
workbooks with a lot of heavy formulas and to calculate all of them
take a time.

Below is my code:

Private Sub App_WorkbookOpen(ByVal wb As Workbook)
'Speed up the process
Application.Interactive = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'Exit from Sub when no workbooks opened
If Application.Workbooks.Count < 1 Then
Exit Sub
End If

'Perform report manipulations here
Call ctApplyFormatting()
Call ctConvertToValues()

'Restoring Application default behaviour
Application.Interactive = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

Thank you in advance.

BR,
Sergiy


--

Dave Peterson