


Within Excel, you have several different options for calling or running a VBA Sub procedure. Otherwise, all of your work designing and coding the VBA application would've been in vain. In the Visual Basic Editor image above, the code window for the Module 1 is displayed.Īs you type your VBA code directly into the code window, the VBA editor helps you to produce valid VBA code by highlighting code that is invalid.Once you've created a macro, you need a way to execute or call it. If you are creating a dialog box to interact with a user, you can use a Userform.ĭouble clicking on any of the objects within the Project Window will open up the associated Code Window, which is where you can type your VBA code.If you are creating a your own Objects, the code for this should be entered into a Class Module.General code (not linked to a specific object) should be entered into a Module.Code that is to be linked to a specific worksheet should be entered into the relevant worksheet object.Code that is to be linked to a workbook should be entered into the relevant workbook object.Select I nsert from the right-click menu and then, from the submenu, select UserForm, Module or Class Module.Įach of the objects discussed above has a code window associated with it, which should be used to store new VBA code according to the following rules:.Within the Project window, right click on the object that you want to add the module to.To create a new Userform, Module or Class Module: You can also add additional Userform, Module and Class Module objects into the project (in the above image, a Module (named Module1) has been added to the VBA project for Book1.xlsm). Worksheet objects, linked to each worksheet of the workbook.A Workbook object, linked to the Excel workbook.

This window provides you with a VBA 'Project' for each currently open Excel Workbook.Ī VBA 'Project' is a collection of all the VBA objects and modules that are linked to the current workbook, and will initially consist of: The Project Window opens up on the left of the VBA Editor (as shown in the above image).
