Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing Application 1

Status
Not open for further replies.

griffinmt

Technical User
Nov 21, 2000
9
US
What is the 'logical' reverse of the following open?

Code:
Set objExcel = GetObject("", "excel.application")
objExcel.Workbooks.open strFullPath

In other words, how do you close the current document AND the workbook. One would think it would be:

Code:
objExcel.ActiveWorkBook.Close
objExcel.Close

but the first line does what is expected, the second line is invalid. Just what am I missing here?
Also, how can you make it close the workbook and NOT prompt for rewriting permission after modifications are made?

Thanks
 
Hi

You going to have to change the statement to the following
Code:
   objExcel.Quit
   'It's probably best to follow that up with
   Set objExcel = Nothing
As for your second question

If unsaved workbooks are open when you use .Quit,
Excel displays a dialog box asking whether you want to save the changes.
This can be prevented by saving all workbooks before using
the Quit method -
Code:
   For Each objWrkBook in objExcel.Workbooks
      objWrkBook.Save
   Next
The other way to do this is to set the DisplayAlerts
property to False. When this property is False, Excel doesn't display the dialog box when you quit with unsaved
workbooks, but it quits without saving them.
Code:
   objExcel.DisplayAlerts = False
NB* You must set this back to True when you done as it's
not done automatically


Another way to do this is to set the Saved property for a workbook to true without saving the workbook to the disk, this sort of "fools" excel into thinking the workbook
is saved. (When you quit excel, it checks this flag to
determine if there are any workbooks to be saved)
Code:
   objWorkBook.Saved = True
   objWorkBook.Close 'This will discard all unsaved changes
THe .Path property of the Workbook object contains an empty string ("") if a workbook is not saved.
Microsoft Excel does not however check this property when you close a workbook
Code:
  Msgbox objWorkBook.Path
Hope this helps
caf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top