最近我設法找到一些關於用戶窗體上的定時器的代碼,我的問題是我需要保持定時器運行,即使用戶窗體或Excel文件是關閉...有人可以看看代碼並提供一些反饋?我的用戶表單是:optionsFormExcel VBA在用戶窗體或Excel關閉時保持用戶窗體定時器運行
Dim dteStart As Date, dteFinish As Date
Dim dteStopped As Date, dteElapsed As Date
Dim boolStopPressed As Boolean, boolResetPressed As Boolean
Private Sub Reset_Timer_Click()
dteStopped = 0
dteStart = 0
dteElapsed = 0
Tech_Timer = "00:00:00"
boolResetPressed = True
End Sub
Private Sub Start_Timer_Click()
Start_Timer:
dteStart = Time
boolStopPressed = False
boolResetPressed = False
Timer_Loop:
DoEvents
dteFinish = Time
dteElapsed = dteFinish - dteStart + dteStopped
If Not boolStopPressed = True Then
Tech_Timer = dteElapsed
If boolResetPressed = True Then GoTo Start_Timer
GoTo Timer_Loop
Else
Exit Sub
End If
End Sub
Private Sub Stop_Timer_Click()
boolStopPressed = True
dteStopped = dteElapsed
End Sub
Private Sub optionsForm_Initialize()
Tech_Timer = "00:00:00"
End Sub
只是一個想法 - 如果excel文件關閉,將表單的值保存在excel的單元格中,然後在打開時繼續。它會像這樣工作嗎? – Vityata
葉,沒有問題....我可以創建和隱藏一個新的選項卡,sheet1爲... – EdN