Hi,
I have VB, which copies the sheet to the new workbook in the same folder, the name of the new file is the same as the source and an extension has been added, which is the name of the sheet I am copying. Everything works ok but I would like it to copy the format as well, and it doesn't work.
Can anyone help me?
I have VB, which copies the sheet to the new workbook in the same folder, the name of the new file is the same as the source and an extension has been added, which is the name of the sheet I am copying. Everything works ok but I would like it to copy the format as well, and it doesn't work.
Can anyone help me?
VBA Code:
Sub SheetCopyRename()
Dim mySourceWB As Workbook
Dim mySourceSheet As Worksheet
Dim myDestWB As Workbook
Dim myNewFileName As String
' First capture current workbook and worksheet
Set mySourceWB = ActiveWorkbook
Set mySourceSheet = ActiveSheet
' Build new file name based
Filename = ActiveWorkbook.Name
If InStr(Filename, ".") > 0 Then
Filename = Left(Filename, InStr(Filename, ".") - 1)
End If
myNewFileName = mySourceWB.Path & "\" & Filename & "_" & mySourceSheet.Name & ".xlsx"
' Add new workbook and save with name of sheet from other file
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=myNewFileName
Set myDestWB = ActiveWorkbook
' Copy over sheet from previous file
mySourceWB.Activate
Cells.Copy
myDestWB.Activate
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
' Resave new workbook
ActiveWorkbook.Save
End Sub