|
▼K.K さん:
>こんばんは。質問内容はタイトル通りで、bookを開いてからを終了させるまでの間、シート上の、例えばA1に常に最新の時間を表示させたいのですが、何かいい方法はないでしょうか?
APIのSetTimerを利用してみました。
標準モジュールに
Option Explicit
Declare Function FindWindow Lib "user32.dll" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Public TimerId As Long
Public Sub TimerProc(ByVal lHwnd As Long, _
ByVal lMsg As Long, _
ByVal lTimerID As Long, _
ByVal lTime As Long)
On Error GoTo TimerProc_Err
Worksheets(1).Range("A1").Value = Format(Now(), "gge年m月d日 h時m分s秒")
Exit Sub
TimerProc_Err:
Timer_End
End Sub
Public Sub Timer_End()
Dim lngRtnCode As Long
If TimerId <> 0 Then
lngRtnCode = KillTimer(Application.hwnd, TimerId)
TimerId = 0
End If
End Sub
ブックモジュールに
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Timer_End
End Sub
Private Sub Workbook_Open()
On Error GoTo Workbook_Open_Err
TimerId = SetTimer(Application.hwnd, 1&, 1000, AddressOf TimerProc)
Exit Sub
Workbook_Open_Err:
Timer_End
End Sub
|
|