VBA Code to include a cell value when saving a new file

robiocco

New Member
Joined
Jan 5, 2015
Messages
10
Hello,

I have the following VBA code that will save each tab as its own file:

Rich (BB code):
Sub Splitbook2()


Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = FalseApplication.DisplayAlerts = False

For Each xWs In ThisWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs Filename:=xPath & "\"& "ABC_GL" & xWs.Name & ".xlsx"
Application.ActiveWorkbook.Close False

Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub


Currently, it will save the tab as "ABC_GL" followed by the name of the sheet. I am trying to do two things:
1) After "ABC_GL" i would want the file name to include whatever is in cell A1
2) Close the newly saved workbook that was created

Thank you for the help!

 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about
Code:
Application.ActiveWorkbook.SaveAs filename:=xPath & "\" & "ABC_GL" & Range("A1").Value & ".xlsx"
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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