Partager via


Writing Solid Code

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

"Writing solid code" means writing Visual Basic for Applications (VBA) code or script that performs as expected and is reusable, easy to understand, and easy to maintain. Many developers focus all their time and effort on just getting code to work. If you have ever struggled to understand code, whether written by you or someone else, or rewritten the same procedure to work in different solutions, then you understand part of the problem.

Other chapters in this book focus on how to develop solutions that perform as expected. This chapter focuses on fundamental coding guidelines and techniques that should be used when developing Microsoft Office solutions. Once these fundamentals become second nature to you, you will discover that your code is easier to understand, debug, modify, and share with others. The techniques discussed in this chapter apply whether you are writing VBA code or script behind an HTML page or Active Server page (ASP).

One of the most important considerations for an effective Office solution is how well it is designed. If your solution has a user interface, you should be aware of consistency and ease-of-use issues every time you create a dialog box or add a custom toolbar. You need to be just as aware of the design and structure of the code you write. The way you design your code, from how you name variables to when you use class modules, can make a big difference in the maintainability and usability of your code.

There is an old adage that says "There is never time to do it right but there is always time to do it over." When it comes to designing and building Office solutions, there should always be time to do it right. It's a lot easier than trying to do it over.

Contents

Using a Naming Convention

Structuring and Formatting Your Code

Using Comments Effectively

Designing Code to Be Used Again

Where to Go from Here