Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Saving a Workbook in a Macro.

Saving a Workbook in a Macro

by Allen Wyatt
(last updated June 5, 2019)


If you want to save a workbook under control of your macro, you can use the Save method. This is the same as choosing Save from the ribbon options, so it will display the Save As dialog box if the document you are saving has not been previously saved. The syntax is as follows:


If you want to save the workbook to a file with a new name, use the following basic syntax:

ActiveWorkbook.SaveAs FileName:="filename"

where "filename" is the full name (including a path), in quotes, that you want used for the file.


If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10769) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Saving a Workbook in a Macro.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Specifying an Index Entry Separator

One of the switches you can use with the index field allows you to specify how index entries should be separated from the ...

Discover More

Creating 3-D Formatting for a Cell

The formatting capabilities provided by Excel are quite diverse. This tip examines how you can use those capabilities to ...

Discover More

Getting Rid of Hyperlinks in Footnotes

When you add hyperlinks to a document, Word makes them active, meaning you can click them to open the target of the ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Excel Not Responding

Have you ever been working with data in Excel and experienced a "freeze" where the program stops responding? This can be ...

Discover More

Making Data Universally Accessible to Workbooks

If you are using Excel as a repository for data used in your business, you may want to figure out a way to make that ...

Discover More

Creating Individual Workbooks

Workbooks can contain many worksheets. If you want to pull a workbook apart and create a whole series of workbooks based ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four less than 5?

2020-11-22 05:03:26

Alan Elston

As an example:
The following macro saves a file with the name Book1.xls on my desktop
It build the file name from the first three cells in the active workbook, as shown in the pic below

Sub Macro1()
Dim ThisFile As String, Ws1 As Worksheet
Set Ws1 = ActiveWorkbook.Worksheets.Item(1) ' First tab worksheet in active workbook
Let ThisFile = Ws1.Range("A1").Value & Ws1.Range("B1").Value & Ws1.Range("C1").Value
ActiveWorkbook.SaveAs Filename:="C:\Users\Elston\Desktop\" & ThisFile & ".xls"
End Sub

(see Figure 1 below)

Figure 1. 

2020-11-22 04:50:02

Alan Elston

Hello Bob
There are probably a few issues, but a few things are not clear form the info that you gave. So we can only give general info.

_ The main issue is probably related to what Allen Wyatt said above….
….”…. filename is the full name (including a path)…..”
I don’t know what you have in cells A1 or B1 or C1 , but the final string you end up with must have a form of like :
Path & "\" & Name & Extension
Path will look something like C:\Users\Elston\Desktop
Name would be something like Book1
Extension might be something like .xlsx

_ You need to be clear about where the macro is, and where the ranges are containing the string information. It is usually best to qualify the ranges fully to give their workbook and worksheet. Just one of many possibilities would be like
That last line example is referring to the first cell in the first worksheet of the active workbook. But I don’t know if that is what you are wanting

Without knowing the exact details of what you are doing, or wanting to do, it is not possible to know exactly what the problem might be

Alan Elston

2020-11-21 10:22:58

Bob Jamison

I would like to have a macro that saves a file according to the values in A1&B1&C1. I found this in a search:

Sub SaveAsA1()
ThisFile = Range("A1").Value & Range("B1").Value & Range("C1").Value
ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub

It does not seem to work. I use a PC, Windows 10, Office 365.
Does anyone have a suggestion?
Thank you.

This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.