Originally Posted by
Kenneth Hobs
Sorry, I did not check the output as I usually do. This can be made faster using some other methods but this is easy to understand. If your filename has illegal characters, it will fail. Some of that can be checked if needed.
[vba]Option Explicit
Sub CaseSheetsAsWorkbooks()
Dim ws As Worksheet, destFolder As String
Dim wb As Workbook, wbs As Worksheet, wbName As String
destFolder = ThisWorkbook.Path & "\"
With Application
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
End With
For Each ws In Worksheets
If Left(ws.Name, 4) = "Case" Then
With ws
wbName = destFolder & .Range("B2").Value2 & "_" & .Range("B3").Value2 & ".xlsx"
If Dir(wbName) <> "" Then Kill (wbName)
Set wb = Workbooks.Add
.Copy wb.Worksheets(1)
For Each wbs In wb.Sheets
If wbs.Name <> .Name Then wbs.Delete
Next wbs
wb.Close True, wbName
End With
End If
Next ws
With Application
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
[/vba]