This video is an introduction into excels programming language called Visual Basic for Applications, or more commonly known as VBA. Having a basic understanding of the Visual Basic Editor, and the language will help you gain access to much more complex customizations of Excel. The great thing about Visual Basic is that it is an open platform for us to add our own code, such as sub routines, or custom functions, and actually run them within Excel. And even if you don't personally know how to create the visual basic code, you can even use the code of others or generate that code through recording your steps using the macro recorder. Either way, you need to have a basic understanding of the Visual Basic environment. And to start, we're going to use the keyboard shortcut of Alt F 11 or simply click on developer And Visual Basic.
This opens up the Visual Basic Editor. And as you will see immediately, there are four distinct parts of the screen. We have the Project Explorer, on the left hand side, the properties window down below the immediate window in the bottom right, as well as the coding window. The most important for our purposes, are going to be the Explorer and the coding window. So I'm going to close that properties and the immediate window. If you'd like to see any of these again, simply move to view and you can turn them on here or using the shortcuts.
As we can see with our project explorer, we actually have a list of every Excel workbook that is open. Here's the workbook that we are currently working in. And although we might simply work in Excel, and notice the different elements of the Excel workbook such as To sheets, we noticed that in Visual Basic, there are several other elements to the Excel workbook. For example, we've got the Excel objects, which include the sheets, and information about this workbook. And then we've got modules. And modules are where the majority of Visual Basic coding is stored.
If you'd like to create a brand new macro, you're going to need to create a module, either by right clicking, moving to insert, choosing module, or, if a brand new workbook has been created, and this doesn't yet have any modules, like we see below. You can select it move to insert, and choose module. Any subroutines or customers functions are created within the coding window. And there are a few simple rules. When creating a subroutine, you must begin with the word sub and then end with the phrase end sub All of the coding must be contained between these two. After the word sub, we provide a name for our macro, followed by a set of parentheses.
The coding window works like any other text editor, you can top copy and paste just as normal. If you'd like to remove a module, you can simply right click on it, move down to remove. an exit will bring up a warning. And this actually asks you if you want to export the module before moving it. So while many people mistakenly click Yes, we should click not. And that removes that module.
You can move back to excel either using the alt tab switching shortcut, or in the top left, you can click on Excel or use the Alt F 11 shortcut. In the next video, we will learn how to generate some of this code and how to copy code in from other workbooks into our we'll see in the next video.