Hi,
I need a macro to close all open workbooks except two of them, named say ab_cd_de.xlsm and fg_hi_jk.xlsx. (using these weird formats because the actual file names are similar (long names with many underscores).
The macro is located in the ab_cd_de file.
I am using the following macro:
For Each Workbook In Application.Workbooks
If Workbook.Name <> "ab_cd_de.xlsm" And Workbook.Name <> "fg_hi_jk.xlsx" Then
Workbook.Activate
Workbook.Close (False)
End If
Next Workbook
I have also tried using the following code:
For Each Workbook In Application.Workbooks
If Not (LCase(workbook.Name) Like "ab_cd_*" Or LCase(workbook.Name) Like "fg_hi_*") Then
Workbook.Activate
Workbook.Close (False)
End If
Next workbook
Both of the codes above fail to retain the two excluded files above and close one of them as well.
In effect I am left with only the fg_hi file for the first stretch of code and the ab_cs file for the second stretch.
Is there any way that I can ensure both of the files remain open after the operation?
Bookmarks