Create First VBA Application in Microsoft Excel 2013


In my previous article I explained about Developer tools in Excel 2013, today we discuss about how to create simple VBA application. Here remember one important thing, VBA macros does not execute in .xlsx files. To execute VBA or macro we have to save file as .xlsm type.

Open Microsoft Office Excel 2013 => select to DEVELOPER menu => Add one ActiveX Command Button by using Insert option as shown below.


 

You can change the button properties like Button Id, Caption…etc through Button properties window. To get the properties window, right click on the button and select properties as shown below.

 


Once you select the properties option, properties window displays as shown below.


                             


Change the Caption value to “Click”. Double click on the window, it opens click event of the button as shown below.


     


Add below code to display some alert box in button click event.


Private Sub CommandButton1_Click()

    MsgBox ("This is the First VBA application")

End Sub


              

 

Now save the file as .xslm. To do that go to File menu => select Save As option and save the file as FirstVBA.xlsm by selecting the Save as type as “Excel Macro Enabled Workbook(*.xlsm)” as shown below.


 


Now click on the “Click” button by unselecting the “Design Mode” option under DEVELOPER tab, it displays the Output as shown below.

 


You can view the code by right click on the sheet name and select View Code. In my next articles we will discuss more about VBA applications.