Excel VBA to save active tab in folder?

jehuh

New Member
Joined
Dec 9, 2021
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Hello All,

I'm running into a snag with saving an active tab as a new excel file in a folder with the filename being the same as the tab name.

Any ideas or code that has worked for you?

thanks!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
The sheet will be saved in the same folder where you have the file with the macro.
Try:

VBA Code:
Sub Macro1()
  Dim nm As String
 
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  nm = ActiveSheet.Name
  ActiveSheet.Copy
  ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & nm & ".xlsx", xlOpenXMLWorkbook
  ActiveWorkbook.Close
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
End Sub

If you want another folder change this:
VBA Code:
ThisWorkbook.Path

For the folder where you want to save, for example:
Rich (BB code):
ActiveWorkbook.SaveAs "C:\work\files" & "\" & nm & ".xlsx", xlOpenXMLWorkbook

--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,896
Members
449,194
Latest member
JayEggleton

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