你是不是厌倦了时间在EXCEL是静态的样子?想体验下EXCEL单元格中动态的时间吗?那就跟我来实现!此需求主要通过VBA来实现!
打开EXCEL,按ALT+F11打开VBA编辑器:
在thisworkbook中输入如下代码:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Terminate
Set appTime = Nothing
Set objBtn = Nothing
End Sub
Private Sub Workbook_Open()
Init (1000)
End Sub
…………………………………………………………………………………………………………..
新建时间Time模块输入如下代码:
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As _
Long, ByVal nIDEvent As Long, ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As _
Long, ByVal nIDEvent As Long) As Long
Dim hTimer
Public objBtn As CommandBarControl
Sub TimerProc(ByVal hWnd&, ByVal Msg&, ByVal idEvent&, ByVal dwTime&)
DoEvents
On Error Resume Next
Range("A1") = Format(Now, "yyyy-m-d hh:mm:ss")
End Sub
Sub Init(Interval&)
hTimer = SetTimer(0, 0, Interval, AddressOf TimerProc)
End Sub
Sub Terminate()
Call KillTimer(0, hTimer)
End Sub
2011/2/25 20:46:23 |
博主你的关键字太抽象了···我觉得应该细化下···/微笑
怎么说?求教!小鸭鸭!0.0