Excel vba的问题:如何用settimer和killtimer写一个代码
答案:1 悬赏:30 手机版
解决时间 2021-01-31 13:45
- 提问者网友:寂寞梧桐
- 2021-01-31 08:24
如何用settimer和killtimer写一个代码,单元格A1每隔一秒随机变换一个颜色(颜色选项10种就可以了),当颜色为红色的时候停止。
最佳答案
- 五星知识达人网友:第幾種人
- 2021-01-31 09:25
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 lngTimerID As Long
Sub g(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long)
xx = Int(Rnd * 10 + 3)
[a1].Interior.ColorIndex = xx
If xx = 3 Then lngTimerID = KillTimer(0, lngTimerID)
End Sub
Sub mystart()
lngTimerID = SetTimer(0, 0, 1000, AddressOf g)
End Sub
(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 lngTimerID As Long
Sub g(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long)
xx = Int(Rnd * 10 + 3)
[a1].Interior.ColorIndex = xx
If xx = 3 Then lngTimerID = KillTimer(0, lngTimerID)
End Sub
Sub mystart()
lngTimerID = SetTimer(0, 0, 1000, AddressOf g)
End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯