none
How to run a VBA program at a specified time in the future? RRS feed

  • Question

  • In Outlook2007, I can not find Application.OnTime this method.
    How to run a VBA program at a specified time in the future? Thanks.
    Saturday, January 21, 2017 8:06 AM

Answers

All replies

  • Leon

    I use the following code in one procedure, and although it is now in Office 2016, I wrote it using Office 2007 and as far as I can recall I have not changed it.

    Private Sub Workbook_Open()
    
    Dim CancelSub As Boolean
    Dim varRunTime
    
        CancelSub = False
        varRunTime = TimeValue("18:45:00")
        Workbooks("Sales_Master Current.xlsm").Activate
        Application.OnTime varRunTime, "UpdateSoldData"
        
    End Sub
    

    Reference for Office 2010 is at https://msdn.microsoft.com/en-us/library/office/ff196165(v=office.14).aspx, and again I am fairly sure 2007 was the same.

    Hope this helps

    Andy C

    Saturday, January 21, 2017 2:40 PM
  • Hello Leon,

    You can set up a timer, see Outlook VBA - Run a code every half an hour for the sample code. 

    Also you may find the Running Outlook Macros on a Schedule article helpful. 


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by leon1526 Sunday, January 22, 2017 3:48 AM
    • Unmarked as answer by leon1526 Sunday, January 22, 2017 3:53 AM
    • Marked as answer by leon1526 Sunday, January 22, 2017 9:57 AM
    Saturday, January 21, 2017 7:48 PM
  • Hi Eugene,Thank you for your answer sincerely.
    I prefer the second solution.Thank you.
    • Marked as answer by leon1526 Sunday, January 22, 2017 3:53 AM
    • Unmarked as answer by leon1526 Sunday, January 22, 2017 3:53 AM
    Sunday, January 22, 2017 3:53 AM