DHTML Timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
'http://www.ka-net.org/office/of12.html | |
'Microsoft HTML Object Library | |
Private d As MSHTML.HTMLDocument | |
Private w As MSHTML.IHTMLWindow2 | |
Private TimerId As Long | |
Public Sub Sample() | |
Call StartTimer | |
MsgBox "タイマー処理を開始しました。" & vbCrLf & _ | |
"タイマーID:" & TimerId, vbInformation + vbSystemModal | |
Call EndTimer | |
MsgBox "タイマー処理を終了しました。", vbInformation + vbSystemModal | |
End Sub | |
Public Sub StartTimer() | |
If TimerId <> 0& Then Exit Sub | |
Set d = New MSHTML.HTMLDocument | |
Set w = d.parentWindow | |
w.onhelp = Me | |
TimerId = w.setInterval("onhelp.TimerProc", 10&, "VBScript") | |
Debug.Print "--- タイマー開始 --- (" & Hex(TimerId) & ")" '確認用 | |
End Sub | |
Public Sub EndTimer() | |
If TimerId = 0& Then Exit Sub | |
Call w.clearInterval(TimerId) | |
TimerId = 0& | |
Set d = Nothing | |
Debug.Print "--- タイマー終了 ---" '確認用 | |
End Sub | |
Public Sub TimerProc() | |
Static n As Long | |
n = n + 1 | |
ActiveSheet.Range("A1").Value = n | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment