Hi Team,
Happy Friday!
I am using following VBA code to close only the workbook I am working on, but this code closes all workbooks which have been opened. Any idea, please.
Happy Friday!
I am using following VBA code to close only the workbook I am working on, but this code closes all workbooks which have been opened. Any idea, please.
Code:
Dim WbCount As Integer, ii As Integer
WbCount = Workbooks.count
If WbCount > 1 Then
For ii = WbCount To 1 Step -1
If Workbooks(ii).Name = ThisWorkbook.Name Then
Application.DisplayAlerts = False
Application.EnableEvents = False
Windows(ThisWorkbook.Name).Close SaveChanges:=False
Application.EnableEvents = True
Application.DisplayAlerts = True
End If
Next ii
Else
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.Quit
Application.EnableEvents = True
Application.DisplayAlerts = True
End If