Results 1 to 6 of 6

Thread: Timer to close excel workbook

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    Rep Power
    0

    Timer to close excel workbook

    Hi,
    I was trying to make a code to close the workbook after a time period (in this code it is set to 30 sec)
    It should give a warning message, before 10 sec of its closing event.
    the code I have is as below.

    But I am little confused that where the code to be pasted.. (in Workbook or in the module)

    Please help..it is not working



    Code:
    Sub close_me()
    ThisWorkbook.Close Savechanges:=True
    End Sub
    
    
    Sub close1_me()
    MsgBox "Please update the file. The file will close with in 10 sec."
    Application.OnTime Now + TimeValue("00:00:10"), "close_Me"
    End Sub
    
     
    Private Sub Workbook_Open()
    Application.OnTime Now + TimeValue("00:00:30"), "close1_Me"
    End Sub
    Last edited by leopaulc; 10-24-2011 at 09:43 AM.

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi Leo,

    Welcome to ExcelFox !!!

    Place the Workbook_Open code in the Workbook module. Place other two subs in a standard module.

    HTH
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi,

    Or you could even try this, which automatically closes the MsgBox.

    Code:
    Sub close1_me()
        
        Dim objWsh          As Object, msg As String
        Const Delay         As Long = 3 'secs ?
        Const wButtons      As Long = 16 ' Boutons + icon
        
        Set objWsh = CreateObject("WScript.Shell")
        msg = "Please update the file. The file will close within 10 sec."
        
        objWsh.Popup msg, Delay, "ExcelFox", wButtons
        Application.OnTime Now + TimeValue("00:00:10"), "close_Me"
    
        Set objWsh = Nothing
    
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    Rep Power
    0
    Hi..
    Thank you .. It works...Gr8

  5. #5
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    Rep Power
    0
    Hi,

    These codes are working smoothly with 2003 version excel workbook.. is there any alternate code for 2007?

    otherwise i have to make the file with macro enabling...

    but i m not prefering to keep the file as macro enabled format...

    Thanks in advance..

  6. #6
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi,

    Without enabling the macro the code won't work either in 2003. I guess your security settings in Excel 2003 is set to Low.

    In XL 2007 you can do this by Click on Office button > Excel Options > Trust Center > Macro settings > check on disable all macros without notification (though it's not recomended )
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Macro To Close All CSV Files
    By Howardc in forum Excel Help
    Replies: 5
    Last Post: 03-15-2014, 05:24 PM
  2. Combobox Not Working In Excel Workbook Shared Mode
    By peter renton in forum Excel Help
    Replies: 15
    Last Post: 06-03-2013, 01:25 PM
  3. Automate Date Changes Within Excel Workbook
    By Danno2cu in forum Excel Help
    Replies: 9
    Last Post: 02-18-2013, 11:39 PM
  4. Replies: 2
    Last Post: 12-04-2012, 02:05 PM
  5. Replies: 2
    Last Post: 12-12-2011, 01:51 PM

Posting Permissions

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