Click here to Skip to main content
15,116,470 members
Articles / Programming Languages / Visual Basic
Article
Posted 17 Feb 2010

Tagged as

Stats

46.8K views
1K downloads
15 bookmarked

VBA Code Tools

Rate me:
Please Sign up or sign in to vote.
3.83/5 (6 votes)
17 Feb 2010CPOL2 min read
Using the VBA Extensibility Library to add comment headers to your code.

Introduction

You have probably heard about all the benefits of commenting your code. If you are really old school, you may have heard about the POYS (the Programmer Over Your Shoulder), that guy that is you from the past telling you what you were thinking when you wrote that nifty (or awful) code snippet.

Of course, most of the time, we do not have the time to bother commenting our code. That is why a couple of shortcuts might help. If you are enforced by someone else to comment your code, this will take some of the burden out of it.

This set of subs create a comment header and insert a 'Modified' date line into an existing comment header, as shown on the code pane on the right:

Image 1

The subs should work fine across Office 2003-2007/VBA6.5 applications, but it has been tested in Access 2003 and 2007 exclusively. Of course, everything has changed again with Office 2010, but I bet there is a lot of applications out there using true and tried VBA.

Using the Code

To use the code, simply create a reference to the extensibility library (as shown in the next image) and import the codetools.bas file into your project.

VBA_Extensibility_1.jpg

To add a comment header to your code, you set the cursor inside a sub or function and type sysaddheader in the debug pane. When you hit Eenter, a comment header is added right above the sub or function (or to the module, if the cursor is not inside a sub or function body).

You can customize the header in any way you want. The default header will include the sub/function (or module) name, the creation date, and the modified date.

Another macro, sysaddmodified, will insert an extra modified date at the bottom of the comment header.

Incidentally, the sys prefix just helps me distinguish code extensibility functions from regular functions.

Points of Interest

Chances are you love reminiscing in your old code or you hate commenting code. Either way, this might save you some of the trouble. For one thing, it is fun to go back to some code pieces that seem to traverse languages and the test of time.

History

First public release.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

hector [.j.] rivas
Software Developer (Senior) Texas Capital Bank
United States United States
Professional software engineer with 30+ years of experience delivering systems across diverse industries, looking for the next opportunity to deliver cutting edge end-to-end technology solutions.

Avid reader, disciplined writer and enthusiastic tinkerer with a background in electronics, looking inside and thinking outside the box, genuinely passionate about robust, extensible, reusable and performant code.

Framework developer leading, coaching and learning about best practices, code quality, DevOps and software and data lifecycle management with an agile mindset to create the most elegant and sustainable solutions.

Comments and Discussions

 
GeneralThumbs up Pin
Member 103757752-Nov-13 3:34
MemberMember 103757752-Nov-13 3:34 
GeneralProblem Pin
shutao10-May-10 10:58
Membershutao10-May-10 10:58 
GeneralRe: Problem Pin
Muller.Ben5-Jun-10 19:25
MemberMuller.Ben5-Jun-10 19:25 
GeneralRe: Problem Pin
hector [.j.] rivas3-Sep-13 3:09
Memberhector [.j.] rivas3-Sep-13 3:09 
GeneralMy vote of 1 Pin
AxelM21-Feb-10 22:54
MemberAxelM21-Feb-10 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.