VBA Save Excel File Example Macro Code

Home/VBA/VBA Save Excel File Example Macro Code

VBA code to save the excel file example code will help us to save the excel file. We can use Save method of Workbook to save the file. In this example we will see how to save the current Excel file using VBA. And this code should work for all the version of Microsoft Excel 2003, Excel 2007, Excel 2010, and Excel 2013.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

BROWSE ALL TEMPLATES

50+ Project Management Templates Pack
Excel PowerPoint Word

VIEW DETAILS

Advanced Project Plan & Portfolio Template
Excel Template

VIEW DETAILS

Ultimate Project Management Template
Excel Template

VIEW DETAILS

20+ Excel Project Management Pack
Excel Templates

VIEW DETAILS

20+ PowerPoint Project Management Pack
PowerPoint Templates

VIEW DETAILS

10+ MS Word Project Management Pack
Word Templates

VIEW DETAILS


vba save excel file

VBA code to save the excel file


Here is the Example VBA syntax and Example VBA code to save the Excel File. This will help you to how to save current Excel workbook using VBA.

VBA Save Excel File: Syntax


Following is the VBA Syntax and sample VBA code to Save the Excel File using VBA. We are using the Save method of the Excel Workbook object.


WORKBOOK.SAVE

Here workbook can be ActiveWorkbook, ThisWorkbook or a workbook assigned to an object.
ActiveWorkbook.Save will Save the currently active Excel Workbook. And ThisWorkbook.Save 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.Save method as shown below:

Dim wb as Workbook
Set wb=Thisworkbook
Wb.Save

Here is explained VBA code:
‘Declaring the wb object as Workbook, in the next statement we will assign the workbook to this object.
Dim wb As Workbook

‘Assigning Thisworkbook to workbook object i.e.; wb.
Set wb = ThisWorkbook

‘And saving the workbook using workbook object which we have created above and Save method of the workbook.
wb.Save

Like this we can assign any workbook to an object. And then we can save the Excel Workbook using Object in VBA.

Save Excel File using VBA : Examples


The following VBA code is to Save the Excel File. This code will save the Workbook which we have this VBA procedure.

Sub sbVBS_To_SaveExcelFile()
    ThisWorkbook.Save
End Sub

Instructions to run the VBA code to save the excel file


Please follow the below steps to execute the VBA code to save the excel file.
Step 1: Open any existing Excel workbook
Step 2: Do some changes
Step 3: Press Alt+F11 – This will open the VBA Editor
Step 4: Insert a code module from then insert menu
Step 5: Copy the above code and paste in the code module which have inserted in the above step
Step 6: Now press F5 to execute the code

Now you can observe that your Excel workbook is saved with the changes.

Explained VBA Code to Save the Excel File


Starting procedure to write VBA code to Save Excel File using VBA.
Sub sbVBS_To_SaveExcelFile_C()

‘To save ThisWorkbook, i.e the workbook with the code module and this procedure. We are using Save method of the workbook to save the excel file.
ThisWorkbook.Save

End Sub
Ending sub procedure.

Here ThisWorkbook object represent the workbook with this code module. And Save is the Workbook method to Save the Excel File. We will see the other examples to save the Workbook in different situations in the next few topics.

LIMITED TIME OFFER - Get it Now!
Advanced Project Plan Excel Template

 
Related Resource External VBA Reference
By |April 22nd, 2014|VBA|0 Comments

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.