In this new and emerging world there are a lot of programming languages and are still increasing out of all those languages the one we need to study is Visual Basic Applications which will really help us in understanding and customizing our Office applications which may save our time in the long run.

The First thing on which most of the people stuck is when they start learning any of the programming language is understanding the Editor where we are going to write our code ? How do we write our code ? What are these terrifying options are for ?

All these questions come to our mind, I personally had these feelings when i first started learning VBA programming and all i wanted was to get some video or sort of a lecture which could help me to understand all this, but unfortunately i didn't find it.

But obviously you may have this luxury as i will tell you each and every option available on Visual Basic Editor that you need to know for your coding journey on VBA. So, stick to this tutorial and enjoy it...


What is The Visual Basic Editor ?

The Visual Basic Editor is not same as Excel but eventually you will get access to it within the Excel. In fact in order for the VBE to be able to run, Excel must be open.

The main function of the VBE is to allow you to write the code within it. It is sometimes called as IDE ( Integrated Development Environment)  you may heard the term IDE it is the environment where we write our code with all the editor features. In this Excel tutorial i will be using the term VBE ( Visual Basic Editor ) so, don't mix it up with VBA.


How To Open The Visual Basic Editor In Excel

I have already made a tutorial on how to access the VBE from the Excel application there are two methods bu the easiest method is to press the shortcut keys "ALT + F11"  and you will be directed to the Editor but, still if you are curious to learn the second method you can read it here.


How Does the Visual Basic Editor Look

The basic VBE window can be divided in the following 5 sections, all of which i will be explaining below there are a lot more windows and options that appear in the screenshot below but still we will cover the important sections.




There's a great possibility that if you open the VBE for the first time then, your Editor may not be as structured as it is in the screenshot above.

You can very easily hide or un-hide any of the windows that is open as VBE has very flexible components so you can very easily adjust windows according to your will.

Let's understand each component one by one of the Visual Basic Editor.


1 : Menu Bar




If you have used any applications or softwares you may be aware of the Menu Bar if you're not these are the options from where we execute our actions with different menu options we have different option an they are like normally Copy, Paste , Save to the Run , Debug and other options .

If you don't want to reach out to the menu bar for every action you need to do then you can very easily look for the keyboard shortcuts for most of the options on the Drop-drown menus.

Some of these shortcuts are given below in the image and you can find more if you need.





Run : 

Run Sub / Userform :-  Runs the current procedure if the cursor is in a procedure, or runs the form is currently active. This command becomes the Continue command when you are in break mode.

Break :- Stops execution of  a program while it's running and switches to break mode. Some editing changes made in break mode may require you to restart your program for the changes to take effect. 


Reset :-  Clears the call stack and clears the module level variables.

Design Mode :-  Turns design mode on per project and then changes to Exit Design Mode. Design mode is the time during which no code from the project is running and events from the host or project will not execute.


Debug :  

Compile VBA Project :-  Compiles your project.

Step Into :-  Executes code one statement at a time.

Step Over :-  Similar to Step Into. The difference in use occurs when the current statement contains a call to a procedure. Step Over executes the procedure as a unit, and then steps to the next statement in the current procedure.



Add Watch :-  Displays the Add Watch dialog box in which you enter a watch expression. Watch expressions are updated in the Watch window each time you enter break mode. 



Insert : 

Procedure :-  Inserts a new Sub, Function, or Property into the active module. Not available if the module is not active.

UserForm :-  Creates a new form and use it to your project.




Module :-  Inserts a new standard module and adds it to your active project.

Class Module :-   Creates a new class module and adds it to your active project.

File :- Displays the Insert File dialog box so that you can insert text from an existing module at the current cursor position.


2 : Toolbar




If you are a computer user, a toolbar is an item that you've probably see many times before. You're probably aware that a toolbar has some on screen buttons, icons, menus and other options that can be used while working with the VBE.

There are three basic toolbars Visual Basic Editor has out of which this image above has the standard and default toolbar other three basic  toolbars are as follows.

  • The Edit toolbar.
  • The Debug toolbar
  • The UserForm toolbar.
You can switch over any of these toolbar by simply going to View  >  Toolbars   and choose your desired toolbar.

Icons displayed are :-


 Run Sub / UserForm or Run Macro - Runs the current procedure if the cursor  in a procedure.

   Break -  Stops execution of program while it's running.

   Design Mode -  Turns design mode off and on.

   Object Browser -  Displays the object browser, these are libraries, classes which can be used in     code.

   Project Explorer -  Displays the project Explorer.

   Properties Window -  Opens the properties Window.

   Reset -  Clears the execution stack module level variables and resets the project.


3 : Project Window / Project Explorer




This window can be useful for the navigation purpose  between sheets, modules , Userform and other
you will clearly see through this section all the workbooks and sheets that are currently open in Excel application.

When you are working in VBE, each open Excel workbook is a project. You can think of a project as a collection of objects arranged as an outline.

You can expand or contract a project by just clicking the (+) and (-) sign given in the project window before projects.



4 : Properties Window






The properties Window displays the properties of the object that is currently selected in the project explorer and allows you to edit those properties respectively.

You can hide or un-hide all of these windows according to your will if you need more space for the coding window or programming window then you can hide all of them and open it whenever you need them. You're likely to work with the properties window in the context of creating Userforms. If you are just beginning to use the VBE, you probably won't need this window too much.

To hide the properties window just right click on the properties window and select hide option in the list and your properties window will automatically disappear.




To un-hide the properties window you just need to go to the View  > Properties window and by clicking on it you window will appear on the screen now it may happen that the window now comes floating so make it set at its place just right click on the properties window again and click on Dockable and it will be adjusted accordingly or you can also drag and drop it wherever you want it to be.




5 : Programming Window / Code Window






This is the Coding window where you will ultimately write your code, now it may happen that if you open your VBE first time your coding window may not appear so to open it you just need to select your object and then click on the code in the view menu will eventually open your coding window.


  • You can also select the object and by clicking on the View Code icon that appears at the top of the project explorer will open the programming window.


  • You can also right click on the object and select View Code out of all the options in the drop-down list and it will again open the coding window.
  • Using the keyboard shortcut which is  "F7"  will also do the same. 




                                                                                                    



Post a Comment

Previous Post Next Post