I have the following code which works perfectly copying all sheets in current workbook to a new workbook. How do I modify so I can choose specific sheets not to copy. Can I use a range with sheetnames?
Code:
Sub CreateUKPBFile()
'Change segment selection to UKPB
Range("D3").Value = "UKPB"
Dim Output As Workbook
Dim Current As String
Dim FileName As String
Set Output = ThisWorkbook
Current = ThisWorkbook.FullName
Application.DisplayAlerts = False
'Loop through each worksheet and copy paste values to new workbook.
Dim SH As Worksheet
For Each SH In Output.Worksheets
SH.UsedRange.Copy
SH.UsedRange.PasteSpecial xlPasteValues, _
Operation:=xlNone, SkipBlanks:=True, Transpose:=False
Next
'Include selected segment in filename
Dim strFilename As String
strFilename = Range("D3").Value
'Get month name for filename
Dim strMonth As String
strMonth = MonthName(3, True)
'Get current year for filename
Dim strYear As String
strYear = Year(Date)
'Create filename
FileName = ThisWorkbook.Path & "\" & strFilename & "_Business_Submission_" & strMonth & "_" & strYear & ".xlsx"
'Output file
Output.SaveAs FileName, XlFileFormat.xlOpenXMLWorkbook
Workbooks.Open Current
'Close output file
Output.Close
Application.DisplayAlerts = True
End Sub