What is the 'logical' reverse of the following open?
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:
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?
Posts: 10
Score: 0
Joined: 5/31/2001
From: USA
Status: offline
Hi
You going to have to change the statement to the following
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 -
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.
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)
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