Excel手动计算其他工作表然后激活

我正在尝试为速度优化设置手动计算工作簿。 主要我想只计算更改应用到它当前表单,所以我使用:

Private Sub Worksheet_Activate() Application.Calculate Application.Calculation = xlCalculationManual End Sub Private Sub Worksheet_Change(ByVal Target As Range) ActiveSheet.Calculate End Sub 

但我有一张纸,我需要手动计算两张纸 – 电stream,第二个。 我尝试了不同的方式Sheet(4).CalculateWorksheets(4).Calculate 。 似乎只有ActiveSheet.Calculate正在工作。 我该怎么做?

如果你不想要一个特定的表来计算,你需要删除Application.Calculate

 Private Sub Worksheet_Activate() Application.Calculation = xlCalculationManual End Sub 

并指定两张表来计算。 带有3张Sheet1不计算的文件:

Sheet1模块(Sheet1更改时):

 Private Sub Worksheet_Change(ByVal Target As Range) Worksheets(2).Calculate Worksheets(3).Calculate End Sub 

Sheet2模块(Sheet2更改时):

 Private Sub Worksheet_Change(ByVal Target As Range) Me.Calculate Worksheets(3).Calculate End Sub 

Sheet3模块(Sheet3更改时):

 Private Sub Worksheet_Change(ByVal Target As Range) Worksheets(2).Calculate Me.Calculate End Sub 

这里是我用来优化Excel设置速度的实用工具

应用程序级别设置

 Option Explicit Public Sub fastWB(Optional ByVal opt As Boolean = True) With Application .Calculation = IIf(opt, xlCalculationManual, xlCalculationAutomatic) If .DisplayAlerts <> Not opt Then .DisplayAlerts = Not opt If .DisplayStatusBar <> Not opt Then .DisplayStatusBar = Not opt If .EnableAnimations <> Not opt Then .EnableAnimations = Not opt If .EnableEvents <> Not opt Then .EnableEvents = Not opt If .ScreenUpdating <> Not opt Then .ScreenUpdating = Not opt End With fastWS , opt End Sub 

工作表级别设置:

 Public Sub fastWS(Optional ByVal ws As Worksheet, Optional ByVal opt As Boolean = True) If ws Is Nothing Then For Each ws In ThisWorkbook.Worksheets setWS ws, opt Next Else setWS ws, opt End If End Sub Private Sub setWS(ByVal ws As Worksheet, ByVal opt As Boolean) With ws .DisplayPageBreaks = False .EnableCalculation = Not opt .EnableFormatConditionsCalculation = Not opt .EnablePivotTable = Not opt End With End Sub 

Excel默认设置:

 Public Sub xlResetSettings() 'default Excel settings With Application .Calculation = xlCalculationAutomatic .DisplayAlerts = True .DisplayStatusBar = True .EnableAnimations = False .EnableEvents = True .ScreenUpdating = True Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets With ws .DisplayPageBreaks = False .EnableCalculation = True .EnableFormatConditionsCalculation = True .EnablePivotTable = True End With Next End With End Sub 

注意:处理完成后,您的代码应该将设置恢复为初始值