Note: The other languages of the website are Google-translated. Back to English
English English

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

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

arrow blue right bubble 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:

doc-save-with-cell-value-1

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?


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

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!
officetab bottom
Comments (33)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
module does not save in .XlsX ; think it has something to do with line 7;; ".xls", FileFormat:=xlNormal; Also how can I modify to take the value from 3 different cells concatenated? for instance: first name , last name , date; in line 6 of the code?
This comment was minimized by the moderator on the site
Dim filename As String
Dim filename1 As String
Dim filename2 As String

Path = "C:\Users\dt\Desktop\my information\"
filename = Range("A1")
filename1 = Range("A2")
filename2 = Range("A3")
ActiveWorkbook.SaveAs filename:=Path & filename & "-" & filename1 & "-" & filename2 ".xls", FileFormat:=xlNormal
This comment was minimized by the moderator on the site
Chris. You can concatinate it in a separate cell and then refernce that cell to be your file name value.
This comment was minimized by the moderator on the site
Hi, Mine will only save as the path and file name. I am only wanting the file name referenced from the cell to save only. Can you please help me?
This comment was minimized by the moderator on the site
This is pretty cool... but there seems to be a bug that I'm not sure how to correct. I'm using this in a macro-enabled template. I open the template, I make changes/updates, I hit F5 to run the macro... and... a "Go To" dialog box pops up expecting me to key a "reference" in. However, if I hit ALT F11, and THEN hit F5, the new .xls file is saved as expected. Do I always need to open up the Visual Basic module to run this "save" procedure?
This comment was minimized by the moderator on the site
I have a template that I don't want to be written over so that the user is required to save the file named by date entered into one of the fields. I don't want the user to have to open tools then select / run macro. They might just as well enter the filename.
This comment was minimized by the moderator on the site
you can add the =NOW() as a parameter to your filename in the cell before you extract it in the Macro (and also place a standard button in the corner of the page so that the emplyee wont have to open any tools
This comment was minimized by the moderator on the site
You guys are lifesavers. Thanks!
This comment was minimized by the moderator on the site
I need to save as a .csv file. how would I change this to make it save as a .csv file? Private Sub filename_cellvalue() 'Update 20141112 Dim Path As String Dim filename As String Path = "C:\Doorlister\import\DoorJob\" filename = Range("AC2") ActiveWorkbook.SaveAs filename:=Path & filename & ".xls", FileFormat:=xlNormal End Sub Thank you in advance for your help!
This comment was minimized by the moderator on the site
I think i did something wrong in here ...

It gives me an error in line Sheets("shitname").Select

Probably i did something wrong when i named the "shitname" like the cell K10

i want to change the sheet to another sheet that is called exactly like the cell K10


' gicsel Macro
'
' Keyboard Shortcut: Ctrl+Shift+C
'
Selection.Copy
Sheets("debagat").Select
Rows("8:8").Select
ActiveSheet.Paste
Dim Path As String
Path = "C:\cgxml\"
Dim filename As String
filename = Range("A8")
Dim shitname As String
shitname = Range("K10")
Sheets("shitname").Select
Application.CutCopyMode = False
ActiveWorkbook.SaveAs filename:=Path & filename & ".xml", FileFormat:=xltxt, CreateBackup:=False
Sheets("TOTAL").Select
ActiveCell.Offset(1, 0).EntireRow.Select
End Sub
This comment was minimized by the moderator on the site
This works great... Thank you, but I need to save as a PDF... Any thoughts?

Thanks

Chris
This comment was minimized by the moderator on the site
same as above but replace ActiveWorkbook.SaveAs with: "ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _"C:\input filenamne.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
This comment was minimized by the moderator on the site
Thanks for your feedback, helped me a lot.
This comment was minimized by the moderator on the site
Hi,
What should i add if I wanted to save the active worksheet but using the sheet 1 cell value?
This comment was minimized by the moderator on the site
Please help... I've managed to do everything. But it saves the docs into My Documents instead of the specified server...



Private Sub CommandButton1_Click()
Dim Path As String
Dim FileName1 As String
Dim FileName2 As String
Dim FileName3 As String
Dim FileName4 As String
Dim FileName5 As String
Path = "J:\Protection Services\Documents\Booysendal security"
FileName1 = Range("A2")
FileName2 = Range("B2")
FileName3 = Range("C2")
FileName4 = Range("D2")
FileName5 = Range("E2")
ActiveWorkbook.SaveAs Filename:=FileName1 & "-" & FileName2 & "-" & FileName3 & "-" & FileName4 & "-" & FileName5 & ".xls", FileFormat:=xlNormal
End Sub
This comment was minimized by the moderator on the site
Add a backslash after security and before the quote... ...security\"
This comment was minimized by the moderator on the site
What if you want to you just want to define the filename but have the option to pick the file path each time you save?

Also can you specify multiple cells for the filename. The cells are merged also.

Save to different file paths each time

Use multiple cells for the filename
This comment was minimized by the moderator on the site
Ok so i got this working good using an in sheet button. Now i would like it to just save normally after the initial save as. Can this be done? Using the same save button?
Thanks Bruce
This comment was minimized by the moderator on the site
how to create a macro to save multiple sheets as with their cell values as file names
Thanks,
Rajiv
This comment was minimized by the moderator on the site
hi all!

How can save repetitive input in the same cells, in other cells, with a Macro?

In sheet1, I input data in A1, B1, C1, for n-times in a day. In sheet2, i need save all this records, in A2, B2, C2, A3, B3, C3, etc. Tnx!
This comment was minimized by the moderator on the site
Hi friends,
I have a problem and would be glad if there is someone to help me
I have a file at drive "F" and folder "ABS" - my filename is "Listdata"
In an Excel file on my desktop I want cells(4,4) to retieve data from "ABS" sheet(1) and cell (2,2)
The below code
Sub Macro1()
activesheet.Cells(4, 4).Value = " F:\ABS\" & listdata & ".xlsx" & Sheets(1).Cells(2, 2).Value
End Sub
but it does not work correctly
Thanks Friends
This comment was minimized by the moderator on the site
Hi, I am trying to use this code but when i try to execute I get a runtime 1004 error and it highlights row 7 as invalid: ActiveWorkbook.SaveAs filename:=Path & filename & ".xls", FileFormat:=xlNormal
How can I resolve this? Im using office 365
This comment was minimized by the moderator on the site
Se a célula de referencia estiver em uma outra planilha já aberta? Como faço?
This comment was minimized by the moderator on the site
Hi. I am very excited it could work but for me in it is saying "BASIC runtime error. Sob-procedure or function procedure not defined." and arrow indicating line 6. What should I do?
This comment was minimized by the moderator on the site
I have a control button for saving as PDF with a specific name to a specific location already working, but I want to modify the code as the filename is the name of the active sheet plus the value of a specific cell from another sheet. How do I do that? This is what I have for saving as PDF:


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
filename:="\\U:\Documents\My_IT_Stuff\T&A\PP11", _
OpenAfterPublish:=False
Application.ScreenUpdating = True
End Sub

Thank you!
This comment was minimized by the moderator on the site
can anyone please help with a solution, i've managed to get the output correctly if the cell is not blank

Private Sub Saveas()

Dim path As String

Dim filename1 As String



path = "C:\User\Compwork\"



filename1 = path & Range("G4") & " " & "-" & " " & Range("G6") & " " & "-" & " " & Range("H7") & " " & "VTError"

Application.DisplayAlerts = False

ActiveWorkbook.Saveas filename1, FileFormat:=52, CreateBackup:=False

ThisWorkbook.Worksheets("report").ExportAsFixedFormat Type:=x1typePDF, Filename:=filename1

Application.DisplayAlerts = True

ActiveWorkbook.Close



End Sub



However, my problem is I'd like to save a filename without leaving a space if the cell value is NULL for instance, if G6 value is blank then i like to the output "G4-H7 VTError".
Any there a way to approach this?


Thanks.
There are no comments posted here yet
Load More
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations