Moving and saving sheets between workbooks using Code Name & Sheet Name

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
184
Office Version
  1. 2013
Hi

I have a workbook with several sheets that I need to move into into new seperate workbooks. The sheet names change each week but the sheet code name remains the same (Sheets 4-8). The new workbooks will be saved in the same folder and take the name of the sheet.

I have found the following code from another thread which I think may be useful:

ActiveSheet.Move

With ActiveWorkbook
.SaveAs Filename:=ThisWorkbook.Path & "" & .Sheets(1).Name & ".xls"
.Close savechanges:=False

End With
Could you help me with how I can refer to the code name to select the right sheet in the code and then take the sheet name as the workbook name?

Thanks
 
How about
Code:
      With ActiveWorkbook
         .SaveAs .path & "\" & Ary(i).name, 51
         .Close
      End With
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
In that case what is the actual sheet name of sheet6?
Also does it move that sheet to a new workbook?
 
Upvote 0
Yes, Sheet6 moves to a new sheet before the error kicks in.

Sheet6 is called "CWDP_HH_1205_Allocate_01"

That name changes every week based upon date change
 
Last edited:
Upvote 0
Ok, this should work
Code:
Sub horizonflame()
   Dim Ary As Variant
   Dim i As Long
   Dim Fname As String
   
   Ary = Array(Sheet6, Sheet7, Sheet8, Sheet9, Sheet10, Sheet11, Sheet12, Sheet13, Sheet14, Sheet15, Sheet16, Sheet17, Sheet18, Sheet19, Sheet20, Sheet21, Sheet22)
   For i = 0 To UBound(Ary)
      Fname = Ary(i).Name
      Ary(i).Move
      With ActiveWorkbook
         .SaveAs ThisWorkbook.path & "\" & Fname, 51
         .Close
      End With
   Next i
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top