Consulting

Results 1 to 5 of 5

Thread: Solved: Show remaining time

  1. #1

    Solved: Show remaining time

    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?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    ThisWorkbook
    [vba]
    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
    [/vba]

    Standard
    [vba]
    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks xld, your code is working perfectly. but the screen is still flickering?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Presumably because of the Ontime resetting cells.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •