Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created March 22, 2012 22:26
Show Gist options
  • Save kumatti1/2165098 to your computer and use it in GitHub Desktop.
Save kumatti1/2165098 to your computer and use it in GitHub Desktop.
DHTML Timer
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