I hope someone can help me with a bit of VBA I need to customise.
I want to copy worksheets into individual workbooks using their tab name.
When copying them over, I need to paste the contents of the worksheets as values only.
I thought I could change the code to ".PasteSpecial Paste:=xlValues"
but this doesn't work for me, it leaves a blank worksheet.
It would be a big bonus if I could also specify which sheets to export instead of exporting everything.
ie "Example sheet 1" , "Example sheet 2" & "Example sheet 3"
I want to copy worksheets into individual workbooks using their tab name.
When copying them over, I need to paste the contents of the worksheets as values only.
I thought I could change the code to ".PasteSpecial Paste:=xlValues"
but this doesn't work for me, it leaves a blank worksheet.
Code:
Sub SaveShtsAsBook()
Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&
MyFilePath$ = ActiveWorkbook.Path & "\" & _
Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4)
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' End With
On Error Resume Next '<< a folder exists
MkDir MyFilePath '<< create a folder
For N = 1 To Sheets.Count
Sheets(N).Activate
SheetName = ActiveSheet.Name
Cells.Copy
Workbooks.Add (xlWBATWorksheet)
With ActiveWorkbook
With .ActiveSheet
.Paste
.Name = SheetName
[A1].Select
End With
'save book in this folder
.SaveAs Filename:=MyFilePath _
& "\" & SheetName & ".xls"
.Close SaveChanges:=True
End With
.CutCopyMode = False
Next
End With
Sheet1.Activate
End Sub
It would be a big bonus if I could also specify which sheets to export instead of exporting everything.
ie "Example sheet 1" , "Example sheet 2" & "Example sheet 3"