VBA In Office Excel 2010

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.

MacroVBA thumb VBA In Office Excel 2010 View in gallery

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.

EditMacro thumb VBA In Office Excel 2010 View in gallery

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.

Macro Code VBAView in gallery

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)

VBA ExecutedView in gallery Please note that we have only given an example of Excel 2010, because VBA is most used here. VBA however is also included in Outlook 2010, Word 2010, PowerPoint 2010, etc.

  • Clark Still

    In Excel 2007, I write messages from VBA to worksheet cells and to the statusbar during long cpu intensive jobs, and they work quite well in showing the progress of my VBA process. In Excel 2010, however, output seems to be suppressed (and the window outline darkened) after 10 sec or so of cpu intensive processing. Of course, when the VBA job completes, the output appears. Anyone know how to turn off the output suppression from VBA before the job is done?

  • Edwar Saliba Júnior

    It’s very good for new programmers!

  • Kodanda80

    I am not able click on edit button, hence this is diabled, so could you please help me to enable the same. Thank you.

  • S.Ghafari

    Thanks for your great tutorial!