VBA Save Active Workbook – Excel Macro Example Code

Home/VBA/VBA Save Active Workbook – Excel Macro Example Code

VBA code to save the Active Workbook example code will help us to save the active excel workbook. We can use Save method of Workbook to save the file. In this example we will see how to save the Active 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

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


VBA code to save Active Workbook


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

VBA save Active Workbook: Syntax


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


ACTIVEWORKBOOK.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 aWb as Workbook
Set aWb=ActiveWorkbook
aWb.Save

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

‘Assigning Thisworkbook to workbook object i.e.; awb.
Set awb = ActiveWorkbook

We are saving the workbook using workbook object which we have created above and Save method of the workbook.
awb.Save

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

Save Active Workbook using VBA: Examples


The following VBA code is to Save the Excel File. This code will save the Active Workbook which we have currently activated.

Sub sbVBS_To_SAVE_ActiveWorkbook()
ActiveWorkbook.Save
End Sub

Instructions to run the VBA code to save Active Excel Workbook


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

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

Explained VBA Code to Save the Active Workbook :


‘STARTING PROCEDURE TO WRITE VBA CODE TO SAVE ACTIVE EXCEL FILE USING VBA
Sub sbVBS_To_Save ActiveWorkbook _C()

‘To save ActiveWorkbook, i.e the workbook which we currently activated (this may or may not contain the the code module and this procedure). We are using Save method of the workbook to save the excel file.

ActiveWorkbook.Save

‘Ending sub procedure
End Sub

Here ActiveWorkbook object represent the workbook which we currently activated. And Save is the Workbook method to Save the Excel File. You can find the example code to save the Workbook in different situations in other topics.

LIMITED TIME OFFER
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


Related pages


sql question and answer pdfexcel vlookup sampleexcel formula is not blankcombobox multiselectvba dsn connection stringddl tutorialcopy worksheet in excelvba excel buttoncreating dynamic charts in excelwhat is operand and operatorvba excel hyperlinkinserting dropdown in excelexcel vba set cell colorvlookup functioninsert comment excelmultiple if statement excelvba excel isnumericmicrosoft excel formulas with exampleshow to open excel file in xml formatcopy and paste cells in excelvba call subcountif samplehow to unprotect excel sheet 2010 with passwordhow to create a 3d pie chart in excelconnect excel to oracle databasehow to delete macros in excelif statement in vbamicrosoft excel if statementsfind duplicate entry in exceldelete duplicates in excel 2003project timelines templatesvlookup excel example 2010access vba input boxvba worksheetmacro password removervba selection deletems access vba create tableexcel macro commandsfileexists vbscriptaccess msgboxlearn macros excelexcel vba example codeactivex combo boxoffset formula in excel with examplegantt chart in excel 2003remove duplicates excel vbaexcel auto enable macrosrecordset excel vbaexcel vba selectionwhat are the ddl commandsnew adodb connection vbaexcel hyperlink to pdfproject plan gantt chart excellistbox multiple selectionexcel vba vlookupaccess vba sql queryexcel dashboard template downloaddashboard reporting with excelmultiple project timeline template excelsql pivot table tutorialexcel vba worksheet namevalue vbaaccess vba delete recordexcel vba project passwordcan you delete duplicates in excelusing concatenate in excelfileline accessvba recordset fieldshow to highlight column in excelexcel vba with sheetshow to do sumif in excelunprotect excel spreadsheet with passwordexcel mark duplicatesshort key to insert row in excel