Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2004
    Posts
    113

    Unanswered: macro to close and exit a speadsheet

    Hey guys,
    what is the code to close a speadsheet and exit out of excel without saving document? As soon as i run the macro, it should exit out fo excel without saving. An example filename would be test.xls

    thanks guys

  2. #2
    Join Date
    Feb 2004
    Posts
    533
    Quote Originally Posted by inho78
    Hey guys,
    what is the code to close a speadsheet and exit out of excel without saving document? As soon as i run the macro, it should exit out fo excel without saving. An example filename would be test.xls

    thanks guys
    Code:
    'To close an active workbook witout saving
    
    ActiveWorkbook.Close SaveChanges:=False
    
    'If the book to close is not active loop through work books
       For Each Book In Workbooks
           If Book.Name = "Name of Your Workbook.xls" Then
             Book.Close SaveChanges:=False
           End If
       Next
    
    'to close the application
    ' Close the Application
        Application.Quit
    
    'You'll need to check or ensure there are not more workbooks open before exiting the application. you can use workbook count
    
    If workbooks.count > 1 Then
      msgbox "Hey dummy close the extra workbooks before clicking this button"
      Exit Sub
    End If

    /
    ~

    Bill

  3. #3
    Join Date
    Sep 2004
    Posts
    113
    thanks man...
    it worked!
    but the thing is, when i have to excel applications open it only closes one application even though im running 2 different macros , 1 macro on each excel application. I say application because they are not 2 workbooks on one excel app, it is 2 diff excel apps. Each macro has the close procedure with the excel file name to close, yet it only closes 1 excel application? how do i get pass this??. When i am finsihed running the macros, no excel programs should be running. what am i doing wrong?

  4. #4
    Join Date
    Feb 2004
    Posts
    533
    Most likely you will use win32 API. Take a look at this for some ideas.

    http://www.tek-tips.com/viewthread.cfm?qid=663482

    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    ~

    Bill

Posting Permissions

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