Saving all workbooks

The following procedure loops through all workbooks in the Workbooks collection and saves each file that has been saved previously:

Public Sub SaveAllWorkbooks() Dim Book As Workbook For Each Book In Workbooks

If Book.Path <> "" Then Book.Save Next Book End Sub

Notice the use of the Path property. If a workbook's Path property is empty, the file has never been saved (it's a new workbook). This procedure ignores such workbooks and only saves the workbooks that have a nonempty Path property.

0 0

Post a comment