Hi Steve
You wont be able to delete the old file from within itself. You would need to use the Kill statement within another Workbook. The code below will open "EXPRESS_PRICING", copy all sheets from the old version into it. Then close iself without saving. All you need to do then is save EXPRESS_PRICING as the old name over the top of the old version.
Sub TransfereOldToNew()
Dim Wsht As Worksheet
Dim OldName As String
Application.ScreenUpdating = False
OldName = ThisWorkbook.Name
Workbooks.Open FileName:="EXPRESS_PRICING.xls"
Windows(OldName).Activate
For Each Wsht In ThisWorkbook.Worksheets
Wsht.Copy Before:=Workbooks("EXPRESS_PRICING.xls").Sheets(1)
Next Wsht
Windows(OldName).Activate
ThisWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub
OzGrid Business Applications
Dave if I delete the line Next wsht and change .sheets(1) to (4) will this only copy sheet4 and last if the name I want the workbook to be named is located in cell A1 of sheet4 is there a way to name the workbook it and then to answer yes to the file already exists do you want to overwrite
thanks steve
Hi Steve
This will copy only one sheet into "EXPRESS_PRICING" then save the file as the name in range A1 without displaying the "do you want to...." message. Just as long as the name is not the same as the other open Workbook.
Sub TransfereOldToNew()
Dim Wsht As Worksheet
Dim OldName As String
Dim NewName As String
Application.ScreenUpdating = False
OldName = ThisWorkbook.Name
Workbooks.Open FileName:="EXPRESS_PRICING.xls"
Windows(OldName).Activate
Sheets("CopySheet").Copy Before:=Workbooks("EXPRESS_PRICING.xls").Sheets(1)
NewName = _
Workbooks("EXPRESS_PRICING.xls").Sheets("YourName").Range("A1")
Application.DisplayAlerts = False
Workbooks("EXPRESS_PRICING.xls").SaveAs NewName & ".xls"
Application.DisplayAlerts = True
Windows(OldName).Activate
ThisWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub
Dave
OzGrid Business Applications