+ Reply to Thread
Results 1 to 13 of 13

OnTime Method error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    179

    OnTime Method error

    I need a macro to run at a certain time on Wednesday's, and then a certain time on the other days.

    I would like to use a cell to reference that time, but right now, I am just hard coding it, but I an not get it to run.

    Ultimately what I am looking for is something like this:

    
    Private Sub Workbook_Open()
         If (Weekday = 3) Then
         
         Application.OnTime TimeValue(Sheet2("E11"), "OpenMaster"
    
         Else
         Application.OnTime TimeValue(Sheet2("E12")), "OpenMaster"
    
    End Sub
    But I was not getting that to work, so then I just did a standard time code to test it, but even then it didn't work.

    Standard code:

    
    Private Sub Workbook_Open()
         Application.OnTime TimeValue("17:10:00"), "OpenMaster"
    
    End Sub
    With the module code:

    Sub OpenMaster()
    
    Application.OnTime
    
      TimeValue ("17:10:00"), "OpenMaster"
    
    Workbooks.Open "G:\Make Your Day Program\8h Grade\Master 8.xls", UpdateLinks:=3
    
    End Sub
    But it didn't work....why? What did I do wrong?
    Last edited by dsrt16; 12-24-2009 at 09:03 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: OnTime Method error

    Hello dsrt16,

    The syntax shown below is correct, provided the cell contains a Time value. Have you tried calling the macro from another procedure other than the Workbook_Open event?
    Application.OnTime TimeValue(Sheet2("E11"), "OpenMaster"
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: OnTime Method error

    If the cell contains a time only, then the sub is scheduled to run today or tomorrow at the specified time, whichever has not yet occurred.

    If you want to schedule it later, you need to include the date.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    179

    Re: OnTime Method error

    shg: I wanted it to occur every day at that time, and I tested it at 5:10 pm, and it didn't run.

    Leith: I am glad to know my syntax is correct, but then again it didn't even run when I coded the time into the macro. I have not called it from anything else. I thought I needed the open event to get it running.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: OnTime Method error

    Try this as a confidence-building exercise, and then modify the code incrementally from there. Demo will run 10 seconds after you run Test.
    Sub Test()
        Application.OnTime Now() + #12:00:10 AM#, "Demo"
    End Sub
    
    Sub Demo()
        MsgBox "The date and time are " & Now
    End Sub

  6. #6
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    179

    Re: OnTime Method error

    Well ultimately I need the code to run at the time listed in the cell. Not incrementally from 12. Example: If the cell says, 2:45, then the code needs to run at 2:45.

+ Reply to Thread

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