+ Reply to Thread
Results 1 to 4 of 4

Close the excel application

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Close the excel application

    Hi Guys

    Can anyone please help me to write vba code for "when we click on a commandbutton then close the excel application in 10 seconds."

    Thanks

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: Close the excel application

    Hi,

    How about this?

    Sub due()
    Application.Wait Now + TimeValue("00:00:10")
    Application.Quit
    End Sub
    You may get a window pop up saking "Do you want to save the changes.."

    To supress this,

    Sub due()
    Application.DisplayAlerts=False
    Application.Wait Now + TimeValue("00:00:10")
    Application.Quit
    End Sub
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Close the excel application

    That works gr8. Thanks Sweep. Can you also tell me how to close the excel application if someone is not using it for about 20 minutes. That means some times people just open the application and don't do anything with this for a long time . Is it possible to close it automatically if the person is not using it for about 20 minutes.
    Last edited by aman1234; 08-26-2010 at 06:33 AM.

  4. #4
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: Close the excel application

    Yes,

    This code goes in the workbook area of the VBA editor.

    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    
    Dim sCountDownTime As String
    Application.OnTime Now + TimeValue("0:20:00"), "ShutDown"
    End Sub
    and this goes in a standard module
    Sub shutdown()
    Application.DisplayAlerts = False
    'ActiveWorkbook.Save
    Application.Quit
    End Sub
    Note that changes made won't be saved, unless you remove the ' from the above code.

+ 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