PC Review


Reply
Thread Tools Rate Thread

All Workbook Saved except This Workbook

 
 
Len
Guest
Posts: n/a
 
      11th Aug 2010
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

 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      11th Aug 2010
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" <(E-Mail Removed)>
wrote in message
news:e3cb90dc-8731-4772-a961-(E-Mail Removed)...
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

 
Reply With Quote
 
Don Guillett Excel MVP
Guest
Posts: n/a
 
      11th Aug 2010
On Aug 11, 6:53*am, Len <ltong2000...@yahoo.co.uk> wrote:
> 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


Here is one I have used for a long time that saves all and quits excel

Sub CLOSE_ALL()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each w In Application.Workbooks
If w.Name <> ThisWorkbook.Name Then
w.Save
End If
Next w
Application.Quit
End Sub
 
Reply With Quote
 
Len
Guest
Posts: n/a
 
      12th Aug 2010
Hi Jim, Don

Thanks for your prompt reply and your codes

Yes, my codes is to saves/closes all OPEN workbooks except the
workbook containing the code.
After work around with your codes, it works great
Below is the revised codes

Sub Button1_Click()
Dim WB As Workbook
For Each WB In Workbooks
If Workbooks.Count > 1 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 "Only 1 workbook open"
Exit Sub
End If
Next

MsgBox "All Workbooks Saved under this Directory Folder "

End Sub

Thanks again

Cheers
Len



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
All Workbook Saved except This Workbook - Part2 Len Microsoft Excel Programming 3 13th Aug 2010 06:50 AM
Why is Referenced Workbook Saved When ActiveWorkbook is Saved? RyanH Microsoft Excel Programming 1 29th Oct 2008 08:20 PM
Save column J of WorkBook when WorkBook is not saved. mikeburg Microsoft Excel Programming 2 14th Jun 2006 09:57 PM
Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ?? WimR Microsoft Excel Programming 9 25th Jul 2005 12:44 PM
Saved Workbook and the Whole workbook is now Protected Beth Microsoft Excel New Users 1 16th Jun 2004 03:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:19 AM.