Save As problems


Posted by Michael on December 28, 2001 8:57 AM

OK here is what I need to be able to do:
I need to have a macro that saves only 6 specific sheets (Named Recap 1-6)to a different file name (hence the save as). However, I do not want any of the formulas in the cells to be saved, only the values that where derived from them (ie insted of =sum(a2+c3) i want the answer (12)to be saved). Does anybody now how to do this in a macro format?

Posted by John on December 28, 2001 9:19 AM

I have recorded a macro that does nearly the same thing. I just copied the information needed, then used pastespecial to paste the format then pastespecial to paste the numbers. I have attached below my code used.

Sub Save_BACT()
'
' Save_BACT Macro

'

'
Range("B4:O59").Select
Selection.Copy
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 4
Range("A4").Select
Workbooks.Add
Columns("B:B").ColumnWidth = 9.67
Columns("C:E").Select
Selection.ColumnWidth = 8.33
Columns("F:F").ColumnWidth = 13.67
Columns("G:H").Select
Selection.ColumnWidth = 8.33
Columns("I:I").ColumnWidth = 9.22
Columns("J:K").Select
Selection.ColumnWidth = 10.22
Columns("L:L").ColumnWidth = 8.33
Columns("M:M").ColumnWidth = 9.67
ActiveWindow.SmallScroll ToRight:=2
Columns("N:N").ColumnWidth = 8.78
Columns("O:O").ColumnWidth = 11.11
ActiveWindow.SmallScroll ToRight:=-2
Range("B2").Select
ActiveWindow.Zoom = 90
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A2").Select
Application.CutCopyMode = False
ChDir "C:\Documents and Settings\jsartain\Desktop"
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\jsartain\Desktop\BACT for Customer.xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
End Sub

Posted by Tom Urtis on December 28, 2001 9:42 AM

Possible solution

Sometimes the slow way is the fast way, or at least the most flexible. Here's a macro that will do what you want, and it will work whether or not you have your destination file open at the time. Also, you can add more sheets to either file and not affect this macro. This assumes you have a destination workbook already set up with the same sheet tab names as the source workbook (Recap 1, Recap 2, etc). I put a bunch of notes in so you can see why and what I did.

Modify as needed.


Sub CopySheets()

'Prepare Excel:
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False

‘Activate the source workbook in case you add code before this that involves another workbook
Windows("Workbook1.xls").Activate
‘Copy the Recap 1 worksheet
Sheets("Recap 1").Cells.Copy

'See if you have the Workbook2 file open; if not then open it:
On Error GoTo b:
Windows("Workbook2.xls").Activate
'If you do not have the file open there will be an error and it will goto b:
GoTo c:
b:
ChDir "C:\Your\File\Path"
Workbooks.Open Filename:="C:\Your\File\Path\Workbook2.xls"
'This will open the file
c:
'Now when we get to c: the Workbook2 file is open either way so we activate it:
Windows("Workbook2.xls").Activate
'Then paste special values into the Recap 1 sheet...
Sheets("Recap 1"). Range("A1").PasteSpecial xlValues

'And continue the data transfer, back and forth from Workbook1 to Workbook2

Windows("Workbook1.xls").Activate
Sheets("Recap 2").Cells.Copy
Windows("Workbook2.xls").Activate
Sheets("Recap 2"). Range("A1").PasteSpecial xlValues

Windows("Workbook1.xls").Activate
Sheets("Recap 3").Cells.Copy
Windows("Workbook2.xls").Activate
Sheets("Recap 3"). Range("A1").PasteSpecial xlValues

Windows("Workbook1.xls").Activate
Sheets("Recap 4").Cells.Copy
Windows("Workbook2.xls").Activate
Sheets("Recap 4"). Range("A1").PasteSpecial xlValues

Windows("Workbook1.xls").Activate
Sheets("Recap 5").Cells.Copy
Windows("Workbook2.xls").Activate
Sheets("Recap 5"). Range("A1").PasteSpecial xlValues

Windows("Workbook1.xls").Activate
Sheets("Recap 6").Cells.Copy
Windows("Workbook2.xls").Activate
Sheets("Recap 6"). Range("A1").PasteSpecial xlValues

'Save and close Workbook2 because we don't need it anymore
ActiveWorkbook.Save
ActiveWindow.Close

‘Reactivate Workbook1, and add more code for other tasks or just end the Sub
Windows("Workbook1.xls").Activate

'Reset Excel back to the way it was before it was open:
Application.CutCopyMode = False
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True

End Sub


Any help???

Tom Urtis



Posted by Michael on December 28, 2001 10:28 AM

Thanks