How to save Excel file with cell value?
When you use a workbook, have you ever thought to save the Excel file based on a cell content? For example, you have “Sale price” in cell A1, and you would like to save the workbook as the name Sale price. Of course, you can type the name into the Save As dialog, and then save it. But this will be an inefficient method in your amount of work. Today, I will talk about a quick trick to solve it.
Save Excel file with specific cell value by using VBA code
Save Excel file with specific cell value by using VBA code
The following VBA code may help you to save your workbook with a specified cell value, please do as follows:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Save Excel file with specific cell value
Private Sub filename_cellvalue()
'Update 20141112
Dim Path As String
Dim filename As String
Path = "C:\Users\dt\Desktop\my information\"
filename = Range("A1")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xls", FileFormat:=xlNormal
End Sub
3. And then press F5 key to execute the code, and your workbook has been named as the cell content of cell A1. See screenshot:
Notes:
1. You can specify any cell value as the file name by just modifying the A1 to other cell reference in the above code.
2. Your active workbook will be saved into the folder of C:\Users\dt\Desktop\my information\ (the last slash must be remained when you paste your location to instead of it) location, you can change the path to your need.
Related articles:
How to save file with date and time in Excel?
How to show file path in title bar or toolbar in Excel?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!