View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone[_2_] Jim Cone[_2_] is offline
external usenet poster
 
Posts: 1,549
Default All Workbook Saved except This Workbook

Your code does not save/close all workbooks in a specific directory.
Your code saves/closes all OPEN workbooks except the workbook containing the code.
Add this before the start of the loop...

If Workbooks.Count = 1 Then
MsgBox "Only 1 workbook open"
Exit Sub
End If
--
Jim Cone
Portland, Oregon USA
http://www.contextures.com/excel-sort-addin.html

..
..
..

"Len"
wrote in message
...
Hi,
After several attempts, it fails to work correctly to save all opened
workbooks in a specific directory folder
It works fine when there are more than one excel files opened
However, in the event if there is no excel file being opened except
this workbook and prompt the message " All workbooks saved " based on
the following codes

Dim WB As Workbook
For Each WB In Workbooks
If Not WB Is Nothing Then
If WB.Name < ThisWorkbook.Name Then
With WB
.Sheets(1).Activate
SheetName = .ActiveSheet.Name
FileExtStr = ".xls": FileFormatNum = 56
.SaveAs Filename:=SheetName & FileExtStr, _
FileFormat:=FileFormatNum
.Close SaveChanges:=True
End With
End If
Else
MsgBox "No Excel File is found"
Exit Sub
End If
Next

MsgBox "All Workbooks Saved under this Directory Folder "

Any helps will be much appreciated and thanks in advance

Regards
Len