This should be as simple simple as can be BUT!!
I have 2 workbooks open; I’m in Book 1 making it the “Active Book”
In Book1 I have testing module that when run is supposed to save and close ALL workbooks.
However, it ONLY saves and closes Book1 (the Active Workbook) BUT not Book2 as well.
I have also tested this (run from Book1)
It closes and saves Book2 and leaves Book1 open (as it is coded to do)
Question is WHY wouldn’t the first code; to save and close BOTH books fully work?
Help as ever is greatly appreciated!!
I have 2 workbooks open; I’m in Book 1 making it the “Active Book”
In Book1 I have testing module that when run is supposed to save and close ALL workbooks.
VBA Code:
Sub Close_All_Files_Save()
'Close all open workbooks and save
Dim wb As Workbook
'Loop through each workbook
For Each wb In Application.Workbooks
'Close the workbooks and save changes
wb.Close SaveChanges:=True
Next wb
End Sub
I have also tested this (run from Book1)
VBA Code:
Sub Close_All_Files_Save()
'Close all open workbooks and save
Dim wb As Workbook
'Loop through each workbook
For Each wb In Application.Workbooks
'Prevent the workbook that contains the code from being closed
If wb.Name <> ThisWorkbook.Name Then
'Close the workbook and save changes
wb.Close SaveChanges:=True
End If
Next wb
End Sub
Question is WHY wouldn’t the first code; to save and close BOTH books fully work?
Help as ever is greatly appreciated!!