Hi, I would like to copy one tab/sheet form my workbook and have it saved to a new file. Can the file be saved under the tab name and placed in the same directory as the original workbook? It would be OK to keep saving over the previous file. I also need the cell formulas changed to values in the process. After searching I see this is a common need but I haven't come across exactly what I need. The closest I have found is the code below which creates the workbook but doesn't save it - I don't know too much about code so I don't know if this code is efficient. It does change the formulas to values. Any help is appreciated.
Sub SampleMacro()
Dim SrcWB As Workbook, TrgtWB As Workbook
Dim Sh As Worksheet
Dim MyArray As Variant, ShName As Variant
Dim Matched As Boolean
Application.ScreenUpdating = False
MyArray = Array("LABELS") 'Change the sheet names as required
Set SrcWB = ThisWorkbook
Set TrgtWB = Workbooks.Add
Application.CopyObjectsWithCells = False
SrcWB.Worksheets(MyArray).Copy Before:=TrgtWB.Worksheets(1)
Application.CopyObjectsWithCells = True
For Each Sh In TrgtWB.Worksheets
With Cells
.Copy
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteColumnWidths
End With
Range("A1").Select
Matched = False
For Each ShName In MyArray
If ShName = Sh.Name Then
Matched = True
Exit For
End If
Next
If Not Matched Then
Application.DisplayAlerts = False
Sh.Delete
Application.DisplayAlerts = True
End If
Next Sh
Application.CutCopyMode = False
Application.ScreenUpdating = False
End Sub
Sub SampleMacro()
Dim SrcWB As Workbook, TrgtWB As Workbook
Dim Sh As Worksheet
Dim MyArray As Variant, ShName As Variant
Dim Matched As Boolean
Application.ScreenUpdating = False
MyArray = Array("LABELS") 'Change the sheet names as required
Set SrcWB = ThisWorkbook
Set TrgtWB = Workbooks.Add
Application.CopyObjectsWithCells = False
SrcWB.Worksheets(MyArray).Copy Before:=TrgtWB.Worksheets(1)
Application.CopyObjectsWithCells = True
For Each Sh In TrgtWB.Worksheets
With Cells
.Copy
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteColumnWidths
End With
Range("A1").Select
Matched = False
For Each ShName In MyArray
If ShName = Sh.Name Then
Matched = True
Exit For
End If
Next
If Not Matched Then
Application.DisplayAlerts = False
Sh.Delete
Application.DisplayAlerts = True
End If
Next Sh
Application.CutCopyMode = False
Application.ScreenUpdating = False
End Sub