PDA

View Full Version : Solved: Show remaining time



sujittalukde
07-11-2007, 04:19 AM
In the WB attached, some comments are also given.
My reqirement is that on opening the file, in cell C1, remaining time (start from 15 min) shall be shown and after 15 minutes of opening the file the code shall close the file without any prompt to save and without saving the file.
How this can be done?

Bob Phillips
07-11-2007, 04:42 AM
ThisWorkbook

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWorkbook.Sheets(1).Range("C1").Value = TimeValue("00:15:00")
Application.OnTime nexttick, "UpdateClock", schedule:=False
ActiveWorkbook.Sheets(1).Range("A5").ClearContents

ActiveWorkbook.Save
End Sub

Private Sub Workbook_Open()
Call UpdateClock
Call test
End Sub


Standard

Public nexttick As Double

Public Sub UpdateClock()
' Updates the clock that's visible
' DIGITAL CLOCK
With ThisWorkbook.Sheets(1)
.Range("A5").Value = CDbl(Time)
.Range("A5").NumberFormat = "hh:mm:ss"
.Range("C1").Value = .Range("C1").Value - TimeValue("00:00:01")
If .Range("C1").Value <= 0 Then
ThisWorkbook.Close savechanges:=False
End If
End With
' Set up the next event one second from now
nexttick = Now + TimeValue("00:00:01")
Application.OnTime nexttick, "UpdateClock"

End Sub

sujittalukde
07-11-2007, 05:13 AM
Thanks xld, your code is working perfectly. but the screen is still flickering?

Bob Phillips
07-11-2007, 05:15 AM
Presumably because of the Ontime resetting cells.

sujittalukde
07-11-2007, 05:24 AM
Thanks.