VBA stands for Visual Basic for Application. As you know that VB (Visual Basic) is one of the great programming languages. If you need to do repeated tasks in excel every day, then it is always recommend to automate such tasks so that you can save time and energy. Macros are a great way of automating tasks in Excel, we have already covered a basic tip on recording and using Macros. Macros basically add VB code to your excel sheet.
Whenever you create a new Macro, Excel adds visual basic code at the back-end, so whenever you run a Macro, this VB code is executed and you get the results on the screen. Lets see how the code is generated when we add a Macro and how you can edit and debug this VB code.
How To View The VBA Code Associated With A Macro
Lets assume that we have created a Macro, as mentioned in the post referenced above, then click the Macro option and choose View Macros.
The Macro’s dialogue box will be displayed, here choose the Macro for which you wish to see the VB code and hit the Edit button.
It will open the Macro as a VB code within the VB Editor which is embedded by default in Excel. In this example, I am showing you the code of a basic macro which displays the “Hello World” message when run.
If you know the fundamentals of Visual basic, then you can write your own code here to further improve your Macro and you can add more functionality to your created Macros by adding pieces of code. The editor displayed in Excel is a typical VB editor with The Project Explorer on the left and the source/design window on the right. All you need is familiarity with the syntax of the programming language.
How To Debug VBA Code
If you have made any changes to a Macro’s code, and you want to test to confirm if it is working fine, then you can do this by debugging and running the code. Press F5 and it will debug and execute the code and you will get the results on the screen. (My Code only contains “Hello World”, so I am able to see it on the screen after debugging and execution)