Forums New posts Search forums. What's new New posts New Excel articles Latest activity. New posts. Excel Articles Latest reviews Search Excel articles. Log in Register. Search titles only. Search Advanced search…. Search forums. Log in. If you forgot your password, you can reset your password. JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding. VBA save file with path and name defined by cell value.

Thread starter sasar Start date Feb 27, Tags cell dim filename path2 string. Joined Feb 27, Messages 8. Hi all, I searched around but could not find an answer to my question. Looking for a VBA that will save my file with a file name defined by cell A1 to a path defined by specific network path and folder name in cell A2.

Tried several versions of codes I found online, but cannot find all the conditions in one place. When I try to merge all the conditions, I keep getting errors. Could you please help?VBA code to save as Workbook to specific folder example code will help us to save as the excel workbook in desired location. We can use SaveAs method of Workbook to save the file. In this example we will see how to save as the Excel workbook using VBA. And this code should work for all the version of Microsoft ExcelExcelExceland Excel We are using the SaveAs method of the Excel Workbook object.

This will take full path to save the workbook. SaveAs will Save the currently active Excel Workbook. And ThisWorkbook. SaveAs will save the workbook which we have written our VBA code. And we can set the workbook to any object and we can save it using WorkbookObject.

SaveAs method as shown below:. Dim awb As Workbook. We are saving the workbook using workbook object which we have created above and SaveAs method of the workbook.

macro to save file in a specific directory and name

Like this we can assign any workbook to an object. This code will save as the Active Workbook into location mentioned in the code. Now you can observe that your Active Excel workbook is saved in the specific location with the changes. We are using SaveAs method of the workbook to save the excel file.

Save Workbook Using Excel VBA to Specific Folder

Here ActiveWorkbook object represent the workbook which we currently activated. You can find the example code to save the Workbook in different situations in other topics. But when done second time then I got message of replace earlier workbook. But I dont want to replace. When you use the same name second time, it will through the error as the file with same name is already exist.

If you want to save the file with different name use the SaveAs method. Example; ActiveWorkbook. Dear Sir, Thank a lot for sharing. Can I save as a file into another location with the same name? Save my name, email, and website in this browser for the next time I comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed. Previous Next. Advanced Project Plan Excel Template. About the Author: PNRao. Related Posts.

Hide Developer Tab in Excel Ribbon. October 8th, 0 Comments. Show or Hide Unload a userform. October 2nd, 1 Comment.Stop searching for VBA code online. Learn more about AutoMacro — A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

Note: opening a workbook in ReadOnly mode prevents the file from being saved. To save the file you will need to use Save As and save the file with a different name. Above, we identified all the ways to specify which workbook to save. You can use those exact same methods to identify workbooks when using Save As. Save As behaves similarly to Save, except you also need to specify the name of the new file.

In fact, Save As has many potential variables to define:. A full description of all of the SaveAs arguments is included below. For now we will focus on the most common examples.

macro to save file in a specific directory and name

Note: These arguments can be entered as string with parenthesis or as defined variables. Keep in mind that this simple code may not be appropriate in all cases. To disable these add this line of code:. Associated Files Download Links. Save the active workbook. Save all open workbooks Save all open workbooks that were not opened ReadOnly Save a workbook defined by a variable Save a workbook defined by a string variable Save a workbook defined by the order it was opened.

Workbooks "savefile. Learn More! Dim wb as workbook. For Each wb In Application. Next wb. If not wb ReadOnly then. End if. Dim wbstring as string. SaveAs "new". Dim wb As Workbook. You may also like some of this related content Contact Us. Automate Excel.Workflow procedures that require employees to sort through random emails to see what to do next run the risk of delayed processes, lost documents, or worse—dozens of duplicate documents scattered among desktop PCs and email servers.

To avoid such risks, many organizations are finding ways to do away with email altogether. If you create your forms in Excel, you can build a macro that will allow employees to press a few keys to submit their forms to the appropriate folder automatically.

This form is created in Excel from an Expense Report template. When the managers receive an email with an expense report attached, they open the attachment, sign it, save it, and then forward it to accounting for processing. To eliminate email from this process, add a macro to the Expense Report template, so that after completing the report, the employee presses a shortcut key to submit the form to a shared network folder.

When the manager presses the same shortcut key, the report is saved to another shared network folder that can be accessed by accounting for processing. To add the macro to the Expense Report template, open the template and then perform these steps:. Notice that this macro assigns certain cell ranges to variables to give the saved file a unique name. FName is equal to the Statement Number entered in cell G4.

Once approved, the filename is saved to another unique name by appending ApprovalName to the file name. Only two copies of the report exist, the original and the approved copy. To use the code in this example to eliminate email from a workflow, just change the cell ranges and folder names to meet your process requirements.

We are using a Purchase Order from one of the workgroup pcs. Copy Application. End Sub How, this can be modified, to save the file in root directory, when the PO file is opened and seved from other workgroup pcs. I'm trying to do what some may consider easy, but I'm stuck needing help with it.

I actually have more complicated macros built into this project and am convinced that I'm just thinking too hard about this one; nonetheless, I'm still stuck and am hoping to find some help.

By Mary Ann Richardson. Follow Tech Sign In Page. Forgot Password? Don't have an account? Sign up. Tuesday April 17, Favorites Tech Sign In Page. Bookmark Tech Sign In Page. Insert the following code at the prompt. Click the File tab in the ribbon, and then click Save As. Assign short-cut keys To assign the short-cut keys to run the macro, follow these steps: On the Developer tab, click Macros in the Code group.

Select the SaveAs macro from the list of macros and then click the Options button. Click OK. Save and close the template.

Eliminate email attachments! Mary Ann Richardson. She has worked as a technical writer, trainer, adjunct professor, conference speaker, and Gartner industry analyst, in a wide range of areas including business process management, database management, business intelligence and analytics, content management, IT infrastructure and MS Office applications.When you use a workbook, have you ever thought to save the Excel file based on a cell content?

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.

Subscribe to RSS

The following VBA code may help you to save your workbook with a specified cell value, please do as follows:. VBA code: Save Excel file with specific cell value.

VBA to Get the File Path and folder path - VBA for file picker and folder picker

And then press F5 key to execute the code, and your workbook has been named as the cell content of cell A1. See screenshot:.

VBA Save As Workbook in Specific Folder Excel Macro

You can specify any cell value as the file name by just modifying the A1 to other cell reference in the above code. Related articles:. How to save file with date and time in Excel? How to show file path in title bar or toolbar in Excel? Log in. Remember Me Forgot your password? Forgot your username? Password Reset.

Please enter the email address for your account. A verification code will be sent to you. Once you have received the verification code, you will be able to choose a new password for your account.

Please enter the email address associated with your User account.

macro to save file in a specific directory and name

Your username will be emailed to the email address on file. How to save Excel file with cell value? Read More Free Download You are guest Login Now. Loading comment The comment will be refreshed after To post as a guest, your comment is unpublished. 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? Sob-procedure or function procedure not defined. What should I do? Hi, I am trying to use this code but when i try to execute I get a runtime error and it highlights row 7 as invalid: ActiveWorkbook.If you've worked with Excel before, you're probably quite familiar with 2 basic commands for saving workbooks:. It may not surprise you to know that, when working with VBA, you can carry out these same activities. In fact, knowing how to save Excel workbooks using VBA is essential.

As you work with Visual Basic for Applications, you'll notice that saving workbooks is one of the most important things your macros can do. Due to the importance of knowing how to save workbooks using VBA, this Excel tutorial focuses on this particular topic:.

In addition to providing some examples of VBA code that you can use to save workbooksI explain the basics surrounding 4 VBA methods that you're likely to encounter and use constantly while saving workbooks.

The following table of contents shows the specific topics that I explain in this Excel tutorial:. I explain how to export an Excel file to PDF using macros, and provide several code examples, here. Save method. Save saves the relevant workbook. In other words, the Workbook. Let's take a look at an example to make this clearer.

Save a file with a specific name by input box in VBA

You can get immediate free access to this example workbook by subscribing to the Power Spreadsheets Newsletter. Notice that the macro has only 1 statement which follows the general syntax of the Workbook. Save method explained above:. In this case, ActiveWorkbook is a simplified reference to the Application. ActiveWorkbook property. This property returns a Workbook object, as required by the Workbook.

The workbook that is returned by the ActiveWorkbook property is, more precisely, the workbook in the current active window. However, it doesn't allow you to determine much in connection with the way the relevant Excel workbook is saved. The workbook is saved and that's pretty much it. When working directly in Excel, you use the Save As command if you want to be able to determine more about the way the actual saving of a workbook takes place.

Things work in a similar fashion within Visual Basic for Applications. More precisely, when working with Visual Basic for Applications, you can use the SaveAs method for these purposes. So let's take a look at:.

The arguments or parameters of a method are what allows you to determine the characteristics of the action that a particular method performs. As explained above, the Workbook. Save method doesn't have any parameters. As a consequence, you can't really determine much about how the relevant workbook is saved.

macro to save file in a specific directory and name

The Workbook. SaveAs method is different. Its 12 parameters allow you to further determine several aspects about the way in which an Excel workbook is saved. In other words, Workbook. SaveAs is more flexible and complex than Workbook. Therefore, it allows you to save a workbook in a particular file. The complete syntax of the Workbook.Once you are done with actual calculations or task, at end of the procedure we generally call a procedure to export or Save the Output File to a Specific Folder or common drive.

Or in other case you may not have the permissions to Save the File in a location, so that you can use SaveAs Option to store the revised or updated file. You can use SaveAs method to Save the File to a specific location. You can Save with the same File Name and Location. You can also set to an object and Save the File. In other method, you use Save Dialog Box.

So that user can choose a specific folder to save the Excel File.

The following example show you how to save an Excel Workbook in Specific folder using SaveAs method:. Set to an Object and Save it, so that it is easy to refer to your workbook to do further tasks. If you are dealing with more than one workbook, you will need this method to access a specific Excel Workbook. So that user can choose desired location to save the file.

You can save the workbook in the same directory of the macro workbook using ThisWorkbook. Path property. You can download the example file and explore it. While Saving the existing workbook or a new excel file with existing name, Excel will prompt a warning message. It will interrupt the procedure and ask user to press yes or no for overwriting a file. You can avoid this by disabling the alerts temporarily and save the workbook with the same name by setting the Application.

Once you are done with the task, you should enable the application alerts by setting the property TRUE. The following example will show you, how to overwrite a file by disabling the application alerts. Your means of describing all in this paragraph is really good, every one be able to easily understand it, Thanks a lot. Having trouble using the below code. Any ideas? SaveAs SaveFile. Verify that the file has not been corrupted and that the file extension matches the format of the file. Hi Rob, I found no issues in your code, you may be using Excel This is great help thanks!

But I am trying to combine two codes but I cannot do it! I would like the macro to save the workbook as a file name taken from a cell and also save in in a certain folder location.!

Please can you help?!!

thoughts on “Macro to save file in a specific directory and name

Leave a Reply

Your email address will not be published. Required fields are marked *