How to calculate the entire book, but not all open?

Is there a way to calculate the entire book, but not all open books in VBA?

I know about

worksheet.Calculate

but it will only do 1 sheet. I also know about

Application.CalculateFull

But I think that it is to recount all open books at the same time.

Is it possible to make only 1 workbook?

Edit: I get the approach:

For Each wks In ActiveWorkbook.Worksheets
    wks.Calculate
Next

but it is very dangerous, if there are links between the sheets between them, then the calculation procedure is important. I know that I can find the exact sequence and apply it, the problem is that on very large books this can be a little complicated

+9
source share
7 answers

After doing some research and testing, first select all the sheets and calculate them later:

Application.Calculation = xlManual
ThisWorkbook.Sheets.Select
ActiveSheet.Calculate 

,

+7

, .

, Application.Worksheets(1).Calculate

: 3 Excel.

8200 , 8000 4 , 200 .

100 . , :

  • Application.Calculate - 4,41
  • ThisWorkbook.Worksheets(1).Calculate - ThisWorkbook.Worksheets(1).Calculate
  • ThisWorkbook.Worksheets(1).Range("R1").Calculate ( 4 ) - 84,64

, .

Dim wks as Worksheet. ... , ThisWorkbook.Worksheets(1) -

, , ActiveWorkbook - . ThisWorkbook (, ) .

+3

ThisWorkbook ,

For Each wks In ThisWorkbook.Worksheets
    wks.Calculate
Next wks
+2

:

Sub CalcBook()
    Dim wks As Worksheet
    Application.Calculation = xlManual
    For Each wks In ActiveWorkbook.Worksheets
        wks.Calculate
    Next
    Set wks = Nothing
End Sub
0

:

Sub Cal_()
    Calculate
End Sub
0

. , ( , 50+, ).

1 . , 5 + 1 , . , .

, , elow - , , , . ( ). .

    EXAMPLE, METHOD DOES NOT WORK
Function Calculate_Workbook(Optional Wb As Workbook)

'Application.calculate will calculate all open books, which can be very slow.
'Looping through all sheets in workbook to calculate can be risky due to formula referencing a cell thats not yet calculated, calculation order may be important.
Dim DicShtVisible As New Dictionary
DicShtVisible.CompareMode = TextCompare
Dim Asht As Worksheet, AWkbk As Workbook    'Previously selected books
Dim Sht As Worksheet

Set Asht = ActiveSheet
Set AWkbk = ActiveWorkbook

If Wb Is Nothing Then Set Wb = ThisWorkbook

Wb.Activate
'Unhide all sheets as can't select very hidden stuff
For Each Sht In Wb.Sheets
    DicShtVisible.Add Sht.Name, Sht.Visible
    Sht.Visible = xlSheetVisible
Next Sht

'Select all sheets and calculate the lot
Wb.Sheets.Select
ActiveSheet.Calculate

'Reapply visibility settings
Dim Key As Variant
For Each Key In DicShtVisible.Keys
    Wb.Sheets(Key).Visible = DicShtVisible.Item(Key)
Next Key

'Reset selections
AWkbk.Activate
Asht.Select

End Function

, , - , "" .

, . .

0
source

We can use

Application.CalculateBeforeSave = True 

and then save the workbook? It may be more subtle to intercept the current value, set if not true, save, reset if it was not true.

0
source

Source: https://habr.com/ru/post/1017021/


All Articles