File to save with name as per cell values

kkravch

New Member
Joined
Jan 7, 2016
Messages
3
Greetings, I need help with the following - is there any way to have a VBA code to save an excel file with name that is combination of values in two cells?

Example:

On a particular spreadsheet, lets call it "spreadsheet1" I have the following values:

A1 = 23456
A2 = 01

I would like to be able to get this file saved automatically as 2345601.xlsx.

Thank you.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Greetings, I need help with the following - is there any way to have a VBA code to save an excel file with name that is combination of values in two cells?

Example:

On a particular spreadsheet, lets call it "spreadsheet1" I have the following values:

A1 = 23456
A2 = 01

I would like to be able to get this file saved automatically as 2345601.xlsx.

Thank you.
Hi kkravch, welcome to the boards.

Try out the following in a COPY of your workbook for testing:

Code:
Sub SaveFile()
ActiveWorkbook.SaveCopyAs "C:\YourFolder\" & Range("A1").Value & Range("A2").Value & ".xlsx"
End Sub

You will need to change where you want the file to be saved to from "C:\YourFolder\" to your desired location.
 
Upvote 0
Thanks, worked perfectly. To finish it all, one more little question - when I finish with ActiveWorkbook.Close, what do I need to add so I don't end up with dialogue "do you want to save the file" produced by Excel? Here is my code:

Code:
Sub Upload()
'
        ActiveWorkbook.SaveAs Filename:= _
        "S:\MyDir\" & Range("B1").Value & Range("C1").Value & ".csv" _
        , FileFormat:=xlCSV, CreateBackup:=False
    ActiveWorkbook.Close
End Sub

thanks again
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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