|
|
|
|
|
|
Excel
|
Save File Based on Value in Cell
|
|
Ease of Use
|
Easy
|
Version tested with
|
2002
|
Submitted by:
|
Jacob Hilderbrand
|
Description:
|
This macro demonstrates how to take the text from a cell and use that as the file name when the file is saved.
|
Discussion:
|
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.
|
Code:
|
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:
|
- Open Excel.
- Alt + F11 to open the VBE.
- Insert | Module.
- Paste the code there.
- Close the VBE (Alt + Q or press the x in the top right corner).
|
Test the code:
|
- Tools | Macro | Macros...
- Put the file name in Cell A1 on Sheet1.
- Select SaveAsExample and press Run.
|
Sample File:
|
SaveAsExample.ZIP 6.75KB
|
Approved by mdmackillop
|
This entry has been viewed 429 times.
|
|