+ Reply to Thread
Results 1 to 5 of 5

Application.OnTime can't find project or library

  1. #1
    Registered User
    Join Date
    08-10-2012
    Location
    Bow Island, Alberta, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question Application.OnTime can't find project or library

    I'm trying to make a sheet auto refresh data every 10 seconds. I'm trying some test code just to figure out what I'm doing and I can't even get it to work.

    Please Login or Register  to view this content.
    It waits the 5 seconds as it should but it won't run the sub. I get the error "Can't find project or library".

    Any ideas?
    Last edited by Cutter; 08-10-2012 at 08:22 PM. Reason: Added code tags

  2. #2
    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: Application.OnTime can't find project or library

    What module are each of the subs in?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    08-10-2012
    Location
    Bow Island, Alberta, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Application.OnTime can't find project or library

    I had tried them in the sheet and workbook objects, but never in a module. I put them in a module and now it works. Thank you.

    Why doesn't it work if they are within the sheet code?

  4. #4
    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: Application.OnTime can't find project or library

    ThisWorkbook and Sheet modules are class modules -- all of their variables and procedures are scoped to the class instance.

  5. #5
    Registered User
    Join Date
    08-10-2012
    Location
    Bow Island, Alberta, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Application.OnTime can't find project or library

    I have a new problem, I have the following code in the ThisWorkbook Module:

    Private Sub Workbook_Open()
    Application.OnTime earliesttime:=Now + TimeValue("00:00:10"), procedure:="Refresh", schedule:=True
    End Sub

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.OnTime earliesttime:=Now + TimeValue("00:00:10"), procedure:="Refresh", schedule:=False
    End Sub

    The start one works, the stop one gives the following error:

    Run-time error '1004':

    Method 'OnTime' of object '_Application' failed

    Do you know why?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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