We can save workbook by using ‘SaveAs’ method of workbook object in Excel VBA. Please find the following brief description about saveas method of workbook object.
Why we need to SaveAS a Workbook using VBA?
When we do any changes in the existing workbook, later we may wanted to see the file without changes. So that we can saves changes to the workbook in a different file using ‘SaveAs’ method of workbook object.
VBA SaveAS Workbook – Syntax
Here is the syntax to SaveAs workbook using VBA.
Workbooks(“Your Workbook Name”).SaveAs(
In the above syntax we are using ‘SaveAs’ method of workbook object to save the workbook in another location with modification(s).
VBA SaveAS Workbook:Example 1
Please find the below example, It will show you how to do saveas workbook.
Sub SaveAs_Workbook() Dim Wkb As Workbook Set Wkb = Workbooks.Add ActiveWorkbook.SaveAs Filename:="C:Sample.xlsm" End Sub
Explanation: In the above example we have created variable named Wkb in the first statement. We have used ‘Add’ method of workbook object to add new workbook and then assigned it to object named Wkb in the second statement. At last in the third statement we have used ‘SaveAs’ method of workbook object to save workbook in another location and the file name is “C:Sample.xlsm” (You can change the file name according to your wish).
VBA SaveAS Workbook – Instructions
Please follow the below step by step instructions to execute the above mentioned VBA macros or codes:
- Open an Excel Workbook
- Press Alt+F11 to Open VBA Editor
- Insert a Module from Insert Menu
- Copy the above code for activating a range and Paste in the code window(VBA Editor)
- Save the file as macro enabled workbook
- Press ‘F5’ to run it or Keep Pressing ‘F8’ to debug the code line by line.
Hi,
I am trying to combine the :
strFileToOpen = Application.GetOpenFilename
Workbooks.Open Filename:=strFileToOpen
with a SaveAs function. I need it becuase I am trying to create a Macro where I need to open a file that is not always named in the same way, have the macro save it with a standard name, for example: Test Sample, and have the macro work on it. The Macro should take the infomartion needed from this file and report it on the main file where the Macro is running. Finally the Macro should delete the “Test Sample” file and save the file where the Macro is running with a new name.
I hope this makes sense enough for you to understand what I am struggling with!
Thanks!
T
how to save as same workbook with cells vales text names
I am trying to do a save as and its function the first time but the second time indicates that i can save with the same name as the open workbook.