0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

テスト56

Posted at
Sub CPU_cntrol()

Dim cs As String
Dim shellObj
Dim i As Long

Set shellObj = CreateObject("WScript.Shell")

'CPU使用率の操作の実験(Excelで負荷がかかりすぎる処理の場合の強制終了を防止したい)
cs = "powercfg /SETACVALUEINDEX SCHEME_BALANCED SUB_PROCESSOR PROCTHROTTLEMAX 50"
shellObj.Run cs

cs = "powercfg /SETACTIVE SCHEME_BALANCED"
shellObj.Run cs

Dim str_path As String
Dim wb As Workbook

str_path = "C:\Users\User\Desktop\VBA練習\PDF\test.xlsx"

'ファイルの開閉をタスクマネージャーのCPU使用率を見ながら確認
'100%に設定して以下の処理を実行すると、速く処理できるがCPU使用率は90%を超える時もある
'50%に設定して以下の処理を実行すると、若干遅くなるがCPU使用率は50%前後を推移...φ(-ω-`*)メモメモ
For i = 1 To 50

    Set wb = Workbooks.Open(str_path)
    wb.Close str_path
    
Next i

'処理が終わってそのままにしても元にはもどらないので、100%に戻すコードを入れる
cs = "powercfg /SETACVALUEINDEX SCHEME_BALANCED SUB_PROCESSOR PROCTHROTTLEMAX 100"
shellObj.Run (cs)

cs = "powercfg /SETACTIVE SCHEME_BALANCED"
shellObj.Run (cs)

End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?