macro to save active worksheet as new workbook, name it and close it.

mdbarbee

New Member
Joined
Oct 25, 2018
Messages
2
Can you create a macro that will copy the active tab/worksheet in a workbook and save it as a new workbook, and close that new workbook. The new workbook should be named whatever the tab/worksheet was named in the original workbook, and the new worksheet should have that same name on its tab, too. The new workbook should be saved in the same location as the original workbook (or it can be saved on my desktop if that makes it any easier). I am using Excel2016.

I have this macro below that pretty much does what I need, except it copies each (and every) worksheet in the original workbook and makes a new workbook for each worksheet. I only need to copy one of the worksheets, not all of them. Here’s that macro in case it can be easily modified:

Sub test()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Copy
ActiveWorkbook.SaveAs Filename:=ws.Name & ".xlsx"
ActiveWorkbook.Close
Next ws
End Sub

Thank you for any assistance you can offer.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi & welcome to MrExcel
Try
Code:
Sub test()
ActiveSheet.Copy
ActiveWorkbook.SaveAs ws.Name & ".xlsx", 51
ActiveWorkbook.Close False
End Sub
 
Upvote 0
I don't know how/why, but I got this to work. I just kept playing around with yours until something worked:

Code:
Sub test()
Dim WS As Worksheet
Set WS = ActiveSheet
 WS.Copy
 ActiveWorkbook.SaveAs Filename:=WS.Name & ".xlsx"
 ActiveWorkbook.Close False
End Sub

Thank you much!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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