Consulting

Results 1 to 5 of 5

Thread: Using 'Ontime'

  1. #1

    Using 'Ontime'

    I have a program that needs to wait a few seconds for data to upload before it continues, and my code isn't pausing (or running "Get_Stats")
    The data is downloaded via development, an I need to pause to make sure it is in before the columns are deleted. Am I missing something? Thank you.

    [vba]
    Sub Main()

    Call Development

    Dim RunWhen As Double
    Const cRunIntervalSeconds = 5 ' two minutes
    Const cRunWhat = "Get_Stats"
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, schedule:=True

    ThisWorkbook.Sheets("Development").Columns("J:BJ").Delete

    End Sub
    [/vba]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Have a look here for some possible solutions
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not sure why you delete after issung the Delete after the Ontime, isn't it that that you wish to wait for? If so

    [vba]

    Sub Main()

    Call Development

    Dim RunWhen As Double
    Const cRunIntervalSeconds = 5 ' two minutes
    Const cRunWhat = "Get_Stats"
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, schedule:=True
    End Sub

    Sub Get_Stats()

    ThisWorkbook.Sheets("Development").Columns("J:BJ").Delete

    End Sub
    [/vba]

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    I'd call the 'Sleep' API, and not mess around with OnTime just to delay a little

    [VBA]
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


    'pass the amount of time (in milliseconds)
    Sub TakeNap(timelength As Long)
    Sleep (timelength)
    End Sub

    [/VBA]

    Paul

  5. #5
    The data is downloaded via development
    By way of MS Query? If so, you might want to consider using the AfterUpdate event...

Posting Permissions

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