VBE Tips I Wish I Knew 5 Years Ago

June 26, 2009 by datapig Leave a reply »

Here a few tips that make the VBE (Visual Basic Editor) a bit friendlier to use. I’m man enough to say that I learned a few of these not too long ago.


Tip 1: Block Comments

It’s easy to take this one for granted if you already know it, but I guarantee there are armies of ‘power users’ that still comment code one line at a time.

Who would think that such a useful feature like commenting whole blocks of data would be hidden away in a toolbar – The Edit toolbar to be exact.

To get to the Edit toolbar, go up to the VBE menu and click View->Toolbars->Edit. Once you’ve activated the Edit toolbar, you can dock it to the top of your screen.

To comment a block of code, simply highlight section of code and click the Comment Block button. Guess what the Uncomment Block button will do.

 

Tip 2: Quick Copy Blocks of Code

You can copy whole blocks of code by holding down the Ctrl key on your keyboard while dragging the block where you need it.

This is an old Windows trick that works even when you drag across modules.

 

 

Tip 3: Jumping between Modules and Procedures

Click Ctrl+Tab to quickly move between modules.

Click Ctrl+Page
Up
or Ctrl+Page Down to move between procedures within a module.

 

 

Tip 4: Jumping directly to your Functions/Variables

If you encounter a Function call or a Variable that you would like to explore, simply click on the function/variable name and press Shift+F2.

This will take you right to it. Pressing Ctrl+Shift+F2 will take you back.

 

 

Tip 5: Procedure View

There’s a game I like to call the “Scrollbar Dance”. It’s when you scroll through your code to find a particular section only to realize you’ve scrolled into the next procedure. You try to remedy this by scrolling up, but you overshoot again into the wrong procedure. This goes on until you’re insane.

The quick fix is to use the “Procedure View” button on the low left hand corner of the VBE. Clicking this will limit scrolling to only the function or procedure you’re in.

The button next to it will take you back to full module view.

 

 

Tip 6: Dragging the Yellow Arrow

I’m not ashamed to admit I learned this ditty only two years ago. I’m not ashamed because I know some of you don’t know this either.

You know that yellow arrow you see when you debug your code? Well, you can drag it up or down to the particular line of code you’re interested in running.

You can use this technique to easily skip bits of code while debugging.

 

Ok. How many of these did you not know? Any VBE tricks or techniques I’ve missed?

Advertisement

12 Responses

  1. Q: How many of these did you not know?
    A: None!
    :D

    Tip 6: this can be done also by moving the cursor to a new line (using the keyboard, the arrows) and then pressing CTRL+F9. This is called “Jump to line”.
    Tip 6b: as discribed above, pressing CTRL+F8 will execute the code to the cursor (run to cursor)

    Tip 7: While in debug mode, pressing CTRL+L will popup the stacks of the calls. With that, you can have the exactly feeling of what sequence of calls your software is performing and not just “have a feel like…hhmm… I’m hereeee…. becaaaauze maybe I come from there… “

  2. JP says:

    You can also indent a block of code by highlighting it and pressing Tab.

    Another thing, not sure if it’s a tip, but there are two great VBE add-ins that make code writing easier: the Smart Indenter add-in and the mouse scrolling fix (can’t recall the name).

  3. Control+Up or Down arrow goes between subs too, but to the line below the sub declaration line.

    Thanks for shift+F2, I’ve been using Definition on the right click menu. It appears that Ctrl+Shift+F2 is equivalent to Last Position.

  4. 1.5 out of 6

    I was using tip #2 in Excel and never thought of using it in VBE.

    As for the toolbars, I activate all of them, they don’t take much space.

    A little caveat on tip #3, the modules need to be open.

    On tip #5…Wow!!!

    Tip #6 will be really useful, a real time-saver.

    Thanks!

  5. Gary Whiteford says:

    Knew: 1, 2, 3 and 6 (don’t remember where I picked them up; probably a combination of somebody else’s blogging and the Help files)

    Didn’t know 4 and 5. Very useful!

    I love learning this way!

  6. Sridhar says:

    Know all of them now :)
    I am sure there are a lot more keyboard shortcuts out there but two of my favorites are as follows:

    CTRL + R to navigate to Project Explorer
    CTRL + F2 to navigate to Procedure Bar

  7. jamescox says:

    My biggest epiphany was one that I read somewhere: turning off the message box that pops up when I mangle the syntax of a line of code – or just move off of it to copy something else to paste into the current line I’m coding.

    It can be turned off in the IDE via

    Tools | Options | Editor | uncheck Auto Syntax Check

    It still shows syntax problems in red, which for me is adequate indication that something is wrong and doesn’t slow me up as much as having to click the OK in the message box…

  8. DataPig says:

    James: That’s a great tip. I forgot about that one. I hate that message.

  9. Jan D'haese says:

    Tip 3: thank you for this one!

    James: thank you for the tip about unchecking the auto syntac check.

    This will save me lots of time :)

  10. Lee says:

    Didn’t know about Shift+F5, will try to use that Thanks!

    I tend to use the ‘step through’ shortcuts quite a lot:
    F8 to step through line by line
    Shift + F8 to ‘step over’ (eg. to get the results of a function rather than having to step though each line of the function)
    Ctrl+Shift+F8 to ‘step out’ of the function (eg. when the VBE has taken me to a complex function & I just want to return to the main sub).

    These are all found on the Debug menu but save so much time *if* you can remember the key combos :)

  11. Lynda says:

    RE: #6 – Oh, that is SO much better than commenting out lines (even with tip #1!), F8-ing far enough, then remembering to un-comment!

    RE: jamescox’s tip – Thanks! That stupid little box has been driving me buggy (pun intended)

  12. Stefan says:

    I’m man enough to admit that I only recently discovered CTRL+Space to autocomplete variable, module, etc names.

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>