I have a problem with "For Each wb In Workbooks". I want to close all workbooks which haven't met certain condition.
Macro randomly close what should be closed. Sometimes it depends which workbook is as Workbook(1). Could you advise?
Code:
Dim wb As Workbook
For Each wb In Workbooks
wb.Activate
If Left(wb.Sheets(1).name, 4) <> "BOM." Then
wb.Close SaveChanges:=False
ElseIf Left(wb.Sheets(1).name, 4) = "BOM." And wb.Sheets(1).Tab.Color = 49407 Or wb.Sheets(1).Tab.Color = 49407 Or wb.Sheets(1).Tab.Color = 5296274 Then
wb.Close SaveChanges:=False
End If
Next
Macro randomly close what should be closed. Sometimes it depends which workbook is as Workbook(1). Could you advise?