Consulting

Results 1 to 4 of 4

Thread: VB on Time

  1. #1
    VBAX Regular
    Joined
    Nov 2018
    Posts
    21
    Location

    VB on Time

    can someone please explain to me why this simple macro wont work unless i manually activate it? i want it to start the timer as soon a user opens the workbook

    Sub OnTime() 
    
    Application.OnTime Now + TimeValue("00:15:00"), "CloseMe"
    End Sub
    
    
    Sub CloseMe()
    
    
    
    
    ThisWorkbook.Save
       ThisWorkbook.Close
    
    
    End Sub
    Last edited by Me00550; 07-22-2020 at 09:16 AM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    1. Not good practice to name your subs with a VBA keyword (.OnTime)

    2. Did you put a call to your OnTime macro in the Workbook_Open event so that it will run when a user opens the workbook?
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Nov 2018
    Posts
    21
    Location
    how do you put a call in the Workbook_Open event?

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    There's lots of information about Excel events online


    Capture.JPG

    Capture2.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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