i need to find a way to delete all the excel workbooks but the active one after some condition is fulfilled. I am new to VBA, so it is possible that I got here some very basic problem (but I couldn't find similar question here on SO). Here's my code:
Sub kill()
Dim wb As Workbook
Dim A As String
A = 2
If A = 1 Then
MsgBox "Everything is fine"
'The if condition is working just fine
Else
Application.DisplayAlerts = False
For Each wb In Application.Workbooks
If Not (wb Is Application.ActiveWorkbook) Then
Application.DisplayAlerts = False
If wb.Path <> vbNullString Then
wb.ChangeFileAccess vbNormal
kill (wb.FullName)
End If
ThisWorkbook.Close SaveChanges:=False
End If
Next
End If
End Sub
The if condition is working well, but VBA seems to have a difficulties with the kill command, which confuses me since the "killing" part is working perfectly when not put inside of the If Not condition.
Thank you very much for any suggestions you could provide.
Best regards, Maritn