How to Save File based on Cell Value in Excel

This post will guide you how to save Excel workbook file with Cell value in Excel. How do I save file using cell contents as file name with VBA Macro in excel.

Save File Based on Cell Value


Assuming that you have a request that save the current workbook file I am working as the value in Cell A1. For example, the value of Cell A1 is testWork, and you want to save the workbook as the name of testWork.

To Save file with Cell Value in Excel, you need to write down an Excel VBA Macro to achieve the result. Just do the following steps:

Step1: open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1
Step2: then the “Visual Basic Editor” window will appear.

Step3: click “Insert” ->”Module” to create a new module.

export each sheet to csv2

 

Step4: paste the below VBA code  into the code window. Then clicking “Save” button.

save file based on cell value1

Sub FileNameAsCellContent()
Dim FileName As String
Dim Path As String
Application.DisplayAlerts = False
Path = "C:\test\"
FileName = Range("A1").Value & ".xlsx"
ActiveWorkbook.SaveAs Path & FileName, xlOpenXMLWorkbook
Application.DisplayAlerts = True
ActiveWorkbook.Close
End Sub

Note: if you want to save workbook as other cell value, you just need to change A1 to other cells.

Step5: back to the current worksheet, then run the above excel macro. Click Run button.

Step6: Let’s see the result:

save file based on cell value2

You might also like:

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar