Save File Based on Value in Cell

Ease of Use


Version tested with


Submitted by:

Jacob Hilderbrand


This macro demonstrates how to take the text from a cell and use that as the file name when the file is saved. 


You may want to save a file with a different name. This macro allows you to simple change the text in a cell (in this case A1 on Sheet1) and the macro will save the file with that name. 


instructions for use


Option Explicit Sub SaveAsExample() Dim FName As String Dim FPath As String FPath = "C:" FName = Sheets("Sheet1").Range("A1").Text ThisWorkbook.SaveAs Filename:=FPath & "\" & FName End Sub

How to use:

  1. Open Excel.
  2. Alt + F11 to open the VBE.
  3. Insert | Module.
  4. Paste the code there.
  5. Close the VBE (Alt + Q or press the x in the top right corner).

Test the code:

  1. Tools | Macro | Macros...
  2. Put the file name in Cell A1 on Sheet1.
  3. Select SaveAsExample and press Run.

Sample File:

SaveAsExample.ZIP 6.75KB 

Approved by mdmackillop

This entry has been viewed 396 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2014 VBA Express