I've inherited an old Excel 2003 file that saves each worksheet in the Masterfile as a separate file. It works great in XL2003 but falls over each time when using XL2007, on the highlighted line that sets the File name.
Code:
Public Sub SaveWorksheet_as_Workbook(SheetName As String, SavePath As String, SaveName As String)
' Create seperate file for each w/s present
Dim NewWorkbookName As String
Dim MasterWorkbook As String
Dim P1Name As String
WorkbookName = ActiveWorkbook.Name
MasterWorkbook = WorkbookName
Application.ScreenUpdating = False
P1Name = SaveName & "_" & SheetName ' SheetName passed from calling procedure
Workbooks.Add xlWorksheet
Sheets("Sheet1").Name = P1Name
ActiveWindow.DisplayGridlines = False
ActiveWorkbook.SaveAs FileName:=SavePath & "\" & P1Name
SaveAs2003_Workbook (PathAndName)
Application.ScreenUpdating = False
Workbooks.Open FileName:=SavePath & "\" & P1Name & ".xls", UpdateLinks:=0 ' ##### This line is highlighted!
Windows(WorkbookName).Activate
Sheets(SheetName).Select
Cells.Select
Selection.Copy
Windows(P1Name & ".xls").Activate
Cells.Select
ActiveSheet.Paste
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveWindow.Zoom = 50
Range("A1").Select
ActiveWorkbook.Save
ActiveWorkbook.BreakLink Name:=SavePath & "\" & P1Name & ".xls", Type:= _
xlExcelLinks
ActiveWorkbook.Close
Range("C3").Select
End Sub
[code]
Unfortunately I'm a complete novice with VB and was hoping someone might be able to amend my code so that not only does it save as an XL2003 (.xls) verion as the default, but works in both XL2003 & 2007 versions.
Any help appreciated.