Results 1 to 2 of 2

use of Application.ontime

Threaded View

  1. #1
    Registered User
    Join Date
    04-30-2009
    Location
    tokyo
    MS-Off Ver
    Excel 2016
    Posts
    43

    use of Application.ontime

    Hello,
    This (see below) is an example of the use of Application.OnTime RunTime.
    It is supposed the wait for 10 seconds and increment sheet1.cells(1,1).value by 15.
    It does not. What am I missing?
    Once it works with "00:00:10", I was hoping to replace "00:00:10" by a string that is the result of the concatenation of h:m:s that a user could input. Is this possible? Do I need to add chr$(34) at the beginning and the end? i.e. is aa going to work as is or aa=chr$(34)+aa+chr$(34)?

    Please advise

    Thank you


    CODE ------------------------------START------------------------
    Public Sub test_run_time()
    Debug.Print Now
    Call TestMacroAutoRun(0, 0, 10)
    Debug.Print Now
    End Sub
    
    Sub TestMacroAutoRun(h, m, s)
    Dim RunTime As Date
    Dim aa As Date
    
    hh = conv(h)
    mm = conv(m)
    ss = conv(s)
    aa = hh + ":" + mm + ":" + ss
    RunTime = Now + TimeValue("00:00:10")
    Application.OnTime RunTime, "zipi"
    Debug.Print aa
    Application.OnTime RunTime, "zipi", , False
    End Sub
    
    Public Function conv(h) As String
    
    If h < 10 Then
    conv = "0" + LTrim(RTrim(Str$(h)))
    Else
    conv = LTrim(RTrim(Str$(h)))
    End If
    If h = 0 Then
    conv = "00"
    End If
    End Function
    
    Sub zipi()
    Sheet1.Cells(1, 1).Value = Sheet1.Cells(1, 1).Value + 15
    End Sub
    CODE---------------------- STOP ---------------------------------
    Last edited by Cutter; 08-14-2012 at 09:58 PM. Reason: Added code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1