/ / Excel VBAパフォーマンスコーディング設定 - excel、vba、excel-vba

Excel VBAパフォーマンスコーディング設定 - Excel、Excel、Excel、Excel

私はコードをスピードアップする方法を研究していますExcelのVBAと私は役立っている以下の設定に出くわしました。私の質問は、以下のコード行を1つの変数に設定して、リスト全体を有効にするためにOnまたはOffに設定できるかどうかです。

speedUpCode = On

下の設定をすべて設定し、オフに設定されている場合は、以下のすべてをTrue / xlCalculationAutomaticに戻します

With Application
.ScreenUpdating = False
.DisplayStatusBar = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
ActiveSheet.DisplayPageBreaks = False "note this is a sheet-level setting

回答:

回答№1の場合は7

私はこれを使う(非常に基本的):

Sub GoFast(Optional bYesNo As Boolean = True)
With Application
.ScreenUpdating = Not bYesNo
.Calculation = IIf(bYesNo, xlCalculationManual, xlCalculationAutomatic)
End With
End Sub

電話をかける True 物事をスピードアップするためのパラメータがない場合は、 False リセットする。

おそらくキャプチャについての上記のコメントさまざまな設定の現在の状態で、元の状態に戻すことができます。また、自分が行っていることをすべて考慮する価値があるかどうかに応じて、すべての設定が常に適切に更新されるわけではありません。


回答№2の場合は3

あなたはそうするために関数を使うことができます...

Function speedUpCode(sStatus As String)

If sStatus = "On" Then
With Application
.ScreenUpdating = False
.DisplayStatusBar = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With

ActiveSheet.DisplayPageBreaks = False "note this is a sheet-level setting

Else if sStatus = "Off" then

With Application
.ScreenUpdating = True
.DisplayStatusBar = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With

ActiveSheet.DisplayPageBreaks = True "note this is a sheet-level setting

End Function

これらを使用してオン/オフを切り替えることができます

  speedUpCode "On"
speedUpCode "Off"

しかし、あなたがターンしていることに留意してください設定のオンとオフを切り替える前に、これらのステータスを確認して、元の設定にリセットすることができます あなたは静的変数でこれを行うことができます