Option Explicit
Const CTIME As String = "0:0:3"
Private nextruntime As Date
Private timerisrunning As Boolean
Sub Start_Timer()
If Not timerisrunning Then
nextruntime = Now() + TimeValue(CTIME)
timerisrunning = True
Application.OnTime EarliestTime:=nextruntime, _
Procedure:="GetData", Schedule:=True
End If
End Sub
Private Sub GetData()
Dim rng As Range
Set rng = Sheets("Sheet2").Range("B65536").End(xlUp).Offset(1, 0)
rng = Sheets("Sheet1").Range("A1")
rng.Offset(0, -1) = Time
timerisrunning = False
Start_Timer
End Sub
Sub Stop_Timer()
If timerisrunning Then
Application.OnTime EarliestTime:=nextruntime, _
Procedure:="GetData", Schedule:=False
timerisrunning = Not timerisrunning
End If
End Sub
Private Sub auto_close()
Stop_Timer
End Sub作者: 沙拉油 時間: 2010-12-7 16:21
[attach]3975[/attach]
像上圖這樣嗎?
把你上圖貼的程式碼,這部分
Set rng = Sheets("Sheet2").Range("B65536").End(xlUp).Offset(1, 0)
rng = Sheets("Sheet1").Range("A1")
rng.Offset(0, -1) = Time
複製代碼
改成底下這樣試試看
Set rng = Sheets("Sheet2").Range("A65536").End(xlUp).Offset(1, 0).Resize(1, 4)