Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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?


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.
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
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Morena · 2 months ago
    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!
  • To post as a guest, your comment is unpublished.
    Izabela · 2 months ago
    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?
  • To post as a guest, your comment is unpublished.
    Bruna · 3 months ago
    Se a célula de referencia estiver em uma outra planilha já aberta? Como faço?
  • To post as a guest, your comment is unpublished.
    Tim · 9 months ago
    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
  • To post as a guest, your comment is unpublished.
    Ahmad · 10 months ago
    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
  • To post as a guest, your comment is unpublished.
    radulus · 1 years ago
    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!
  • To post as a guest, your comment is unpublished.
    Rajiv · 1 years ago
    how to create a macro to save multiple sheets as with their cell values as file names
    Thanks,
    Rajiv
  • To post as a guest, your comment is unpublished.
    Bruce McIntyre · 2 years ago
    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
  • To post as a guest, your comment is unpublished.
    Janice Burbage · 2 years ago
    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
  • To post as a guest, your comment is unpublished.
    Stef · 2 years ago
    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
  • To post as a guest, your comment is unpublished.
    Keenan · 2 years ago
    Hi,
    What should i add if I wanted to save the active worksheet but using the sheet 1 cell value?
  • To post as a guest, your comment is unpublished.
    Chris · 2 years ago
    This works great... Thank you, but I need to save as a PDF... Any thoughts?

    Thanks

    Chris
    • To post as a guest, your comment is unpublished.
      Martin S · 2 years ago
      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
  • To post as a guest, your comment is unpublished.
    Kelvin · 2 years ago
    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!
    • To post as a guest, your comment is unpublished.
      George · 2 years ago
      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
  • To post as a guest, your comment is unpublished.
    Ionel D · 2 years ago
    You guys are lifesavers. Thanks!
  • To post as a guest, your comment is unpublished.
    Ken Gaines · 3 years ago
    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.
    • To post as a guest, your comment is unpublished.
      Martin S · 2 years ago
      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
  • To post as a guest, your comment is unpublished.
    Greg · 3 years ago
    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?
  • To post as a guest, your comment is unpublished.
    Alana · 3 years ago
    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?
  • To post as a guest, your comment is unpublished.
    Dan · 3 years ago
    Chris.
    You can concatinate it in a separate cell and then refernce that cell to be your file name value.
  • To post as a guest, your comment is unpublished.
    Chris · 4 years ago
    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?
    • To post as a guest, your comment is unpublished.
      Shaun · 20 days ago
      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