I have this code that, in an existing open workbook (let's call it "Template"), looks for any tabs that have a name begining with "CC". For each of these tabs, it copies the tab into a new workbook, deletes any extra tabs, then saves the new workbook to my desktop.
Sub Copy_Save_CC()
Dim wb As Workbook
Dim NewBook As Workbook
Dim ws As Worksheet
Dim ws2 As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
If UCase(Left(ws.Name, 2)) = "CC" Then
Set NewBook = Workbooks.Add
With NewBook
.Title = ws.Name
ws.Copy After:=NewBook.Worksheets("Sheet3")
For Each ws2 In NewBook.Worksheets
If ws2.Name <> ws.Name Then
ws2.Delete
End If
Next
.SaveAs Filename:="C:\Users\lmcginle\Desktop\" & ws.Name
.Close
End With
End If
Next
wb.Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I want to change this to open an existing workbook (let's call it "Template2") instead of creating a new workbook.
So:
For each tab in "Template" that starts with "CC"
Open "Template2"
Copy CC worksheet into "Template2"
Save "Template2" to my desktop, with a name that is equal to the sheet name and close.
Close "Template2"
Repeat for each tab in "Template" that begins with "CC"
I've tried a couple iterations of code but none worked. I've now spent 6 hours trying to write it myself so would like some assistance if possible. Thanks.
Sub Copy_Save_CC()
Dim wb As Workbook
Dim NewBook As Workbook
Dim ws As Worksheet
Dim ws2 As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
If UCase(Left(ws.Name, 2)) = "CC" Then
Set NewBook = Workbooks.Add
With NewBook
.Title = ws.Name
ws.Copy After:=NewBook.Worksheets("Sheet3")
For Each ws2 In NewBook.Worksheets
If ws2.Name <> ws.Name Then
ws2.Delete
End If
Next
.SaveAs Filename:="C:\Users\lmcginle\Desktop\" & ws.Name
.Close
End With
End If
Next
wb.Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I want to change this to open an existing workbook (let's call it "Template2") instead of creating a new workbook.
So:
For each tab in "Template" that starts with "CC"
Open "Template2"
Copy CC worksheet into "Template2"
Save "Template2" to my desktop, with a name that is equal to the sheet name and close.
Close "Template2"
Repeat for each tab in "Template" that begins with "CC"
I've tried a couple iterations of code but none worked. I've now spent 6 hours trying to write it myself so would like some assistance if possible. Thanks.