Your coding is half done by the VBA editor itself.įor example, type MsgBox “Best Wishes to You!” in the sub procedure Button1_Click (). A sub procedure Button1_Click () is inserted in the Module2 code.Code window with title Module2 (Code) appears.A new module – Module2 is inserted in the Project Explorer.Click in the worksheet where you want to place the command button.
Select the button icon from Form Controls. Write the code stating the actions to take place when you click the command button.Ĭlick the DEVELOPER button on the Ribbon. Next, create a second macro in the same workbook – this time by writing VBA code. Your macro enabled workbook – MyFirstMacro.xlsm appears as a VBA Project.Īll the worksheets and the workbook appear as Microsoft Excel Objects under the project. You will observe the following in the Projects Explorer window − VBA Objects and Modulesīefore you start coding for a Macro, understand the VBA Objects and Modules. In this chapter, you will learn where and how to write the code for a macro. You can create a macro by writing the code in the VBA editor.