macro save and close multiple open excel

0

If someone can tell me how to save and close multiple open excel from an excel with macro

Sub SaveAll()   
    Dim Wkb As Workbook
    For Each Wkb In Workbooks
        If Not Wkb.ReadOnly And Windows(Wkb.Name).Visible Then
            Wkb.Save
        End If
    Next
End Sub

that code does not save the edited data in their respective excel and the files are bugged.

    
asked by Nicolas 26.08.2016 в 22:34
source

1 answer

2

Use something like that in the PERSONAL.XLSB file so that it is available in all files:

Sub SaveAll()
    Dim Wkb As Workbook
    For Each Wkb In Workbooks
        If Wkb.Name <> ActiveWorkbook.Name 
            If Wkb.ReadOnly = False Then
                Wkb.Close SaveChanges:=True
            Else
                Wkb.Close SaveChanges:=False
            End If
        End If
    Next Wkb
    ActiveWorkbook.Close SaveChanges:=True
End Sub
    
answered by 19.10.2016 в 07:58