I'd like to add a function to this sub that checks if any other excel workbook is open. If not then close excel application.
[VBA]
Sub CloseForceSave()
'Save the workbook, then close it
ThisWorkbook.Close savechanges:=True
End Sub
[/VBA]
I'd like to add a function to this sub that checks if any other excel workbook is open. If not then close excel application.
[VBA]
Sub CloseForceSave()
'Save the workbook, then close it
ThisWorkbook.Close savechanges:=True
End Sub
[/VBA]
Hi Rejje,
Try this:
HTHSub CloseForceSave() 'Save the workbook. ThisWorkbook.Save 'If this is the only workbook opened in the current session, then... If Workbooks.Count = 1 Then '...quit Excel Application.Quit 'Else... Else '...close the active workbook ThisWorkbook.Close End If End Sub
Robert
You're a good teacher - many, many thanks!
You're welcome