Hello All,
I am in a roadblock right now and I really need some help on the code below. What I wanted to do is close all opened workbooks. This code does the work IF there is at least one or more opened workbooks.
My problem is IF there is NO opened workbook at all; It goes around unendlessly in the WHILE Loop. How do I not process the closing IF there is no any opened workbook at all? (NOTE: I found this code from somewhere else.)
Again, thank you in advance for helping a poor confused student.
cheers, Dor
'--------------------------------------------
Public Sub CloseAllWorkbooks()
Dim objOffice As Excel.Application
Dim WBook As Excel.Workbook
On Error Resume Next
While Err.Number = 0
objOffice = GetObject(, "Excel.Application")
objOffice.DisplayAlerts = False
For Each objWindow As Excel.Workbook In objOffice.Windows
objWindow.Activate()
WBook = objOffice.ActiveWorkbook
WBook.Saved = True
WBook.Close()
Next
objOffice.DisplayAlerts = True
objOffice.Quit()
objOffice = Nothing
End While
End Sub
'--------------------------------------------