If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > macro to close and exit a speadsheet

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-10-04, 12:55
inho78 inho78 is offline
Registered User
 
Join Date: Sep 2004
Posts: 113
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
Reply With Quote
  #2 (permalink)  
Old 12-12-04, 23:07
savbill savbill is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 12-13-04, 19:19
inho78 inho78 is offline
Registered User
 
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?
Reply With Quote
  #4 (permalink)  
Old 12-14-04, 00:20
savbill savbill is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On