1Option Explicit
2Dim fStop As Boolean 'グローバル変数を宣言
3Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
45Sub グラフ描画開始()
6 fStop = False
7 Do While True ’無限ループ
8 Call データ更新
9 Sleep 1 '描画速度を変えたい場合値を大きくすると更新頻度が下がる。
10 DoEvents
11 DoEvents 'グラフを更新するために2個必要
12 If fStop = True Then
13 MsgBox "グラフ更新停止"
14 Exit Do
15 End If
16 Loop
17End Sub
1819Public Sub 停止ボタン()
20 fStop = True
21End Sub
2223Sub データ更新()
24 'WMIにて使用する各種オブジェクトを定義・生成する。
25 Dim oClassSet As Object
26 Dim oClass As Object
27 Dim oLocator As Object
28 Dim oService As Object
29 Dim CPU使用率 As Long
30 Dim Tmp As Variant 'グラフデータをずらすために使う
3132 'ローカルコンピュータに接続する。
33 Set oLocator = CreateObject("WbemScripting.SWbemLocator")
34 Set oService = oLocator.ConnectServer
35 'クエリー条件を WQL にて指定する。
36 Set oClassSet = oService.ExecQuery("Select * From Win32_Processor")
37 'コレクションを解析する。
38 For Each oClass In oClassSet
39 CPU使用率 = oClass.LoadPercentage
40 Next
4142 Tmp = Range("C6:C103").Value 'CPUの使用率が格納されているセル
43 Range("C5:C102").Value = Tmp '1セルずらす
44 Range("C103").Value = CPU使用率 '最後のセルに最新の値を入れる。
4546 '使用した各種オブジェクトを後片付けする。
47 Set oClassSet = Nothing
48 Set oClass = Nothing
49 Set oService = Nothing
50 Set oLocator = Nothing
51End Sub
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。