Friday, March 28, 2014

Different Colours Used in VBA Window


VBA highlights text in different colours in different situations. Understanding what they mean would help much. Let’s see about that in this post.

Font Highlighted in Black

All is well here. All text that is in black colour is normal code that will be executed by VBA.




Font Highlighted in Red

If entire line of code font is highlighted in red, that means there is a syntax error. Syntax error occurs because of various reasons. Example: can be a misspelt keyword or argument.




Font highlighted in Green

Comment text is highlighted in green. See if there is an apostrophe (‘) from where the text is appearing green. Comments are used to elaborate what the code means or generally to give more information. VBA will not execute comments.




Background highlighted in Grey

Grey highlighted text as shown in below picture means you selected that text. It’s ready to be cut, copied or moved to other location.




Background highlighted in Yellow

This means highlighted line is the execution point. This is the line that will be executed when you proceed further. An arrow mark will be placed in the left hand side of that line. Often  you can see this when you press F8 in the macro.




Background highlighted in Maroon

This means highlighted line is the break point. When you run your code, execution will automatically stop at this line. You can place breakpoint or remove at any line of the code by pressing F9 key placing cursor on that line. A maroon colour circle will also be placed to the left of the code along with highlighting.





Font Highlighted in Blue

If you use any key word that is part of VBA build in statements, functions; that word will be highlighted with blue. Notice colour of With qualifier below. (May be difficult to see here, you may type the same statement in your VBA and notice)




Turquoise Colour Box in the Left

This box refers a bookmark. Bookmarks are used to return to that line of code quickly from anywhere at a later point of time.




Green Arrow in the Left

This is called Call Return Text. When you have a series of macros called from one another and stop the code at a break point, this arrow indicates from where the code will start running when the code is resumed.




Follow this example to see how this works. Copy and paste below code in your module.
Sub Test()
Call Test1
End Sub
Sub Test1()
Call Test2
End Sub
Sub Test2()
Call Test3
End Sub
Sub Test3()
ActiveCell.Select
End Sub
Select ActiveCell.Select line and press F9. This should add a break point on that line (maroon colour highlight). Now click on Sub Test () line and press F5, when the maroon line turns yellow (execution point), press Ctrl+L. This would show a box called Call Stack. Double click anything in the list other than first item. You should be able to see the green arrow in the module that calls your double clicked module. Bit confusing but this is a great debugging tool. You might not be using it if you are not really deep in developing. I myself haven’t used it yet.

All these colours are by default applied by VBA; however you have option to choose other colours you fancy. Click on Tools > Options > Editor Format tab. Under Code Colors, click on any item and you can change the font, size, foreground, background & indicator colour of that item. Enjoy!!!

4 comments:

  1. Please continue this great work and I look forward to more of your awesome blog posts.
    excel vba courses london

    ReplyDelete
  2. Graceful written content on this blog is really useful for everyone same as I got to know. Difficult to locate relevant and useful informative blog as I found this one to get more knowledge but this is really a nice one.
    ไฮไลท์ฟุตบอล

    ReplyDelete