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.
Step2: then the “Visual Basic Editor” window will appear.
Step3: click “Insert” ->”Module” to create a new module.
Step4: paste the below VBA code into the code window. Then clicking “Save” button.
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: