Microsoft Office Tutorials and References
In Depth Information
If a line of code goes beyond the edge of the Code window, you can type a space fol­
lowed by an underscore to indicate that the code on the following line belongs with the
code on the current line. The PermissionLoop procedure on page 81 is the first of many
procedures that use this convention.
Pick a naming convention, and stick with it. Projects, procedures, variables, and other
programming elements all need names. The name should be something meaningful
that conveys what the element is used for. There are a number of naming conventions
that you could choose from, and most are usually some form of Hungarian notation.
Note Hungarian notation is named after the native country of Dr. Charles Simonyi, the
inventor of this naming style. Dr. Simonyi was Chief Architect at Microsoft when he designed
the convention. The original chapter of Programming Windows that described how to use it
can be found by going to http://msdn.microsoft.com/ and typing Simonyi Hungarian Notation
in the Search box.
Choose names that are as concise as possible. While descriptive names are desired,
names greater than 10 to 15 characters become cumbersome to type. Use abbreviations
where they make sense to keep names short. Remember: The longer the name, the
greater the likelihood of it being mistyped.
Developing Projects with the Project Explorer
You use the Project Explorer to manage your projects and modules within the Visual Basic
Editor. It lets you create new modules, delete modules, and copy modules from one project to
another. About the only thing you can’t do in the Project Explorer is create a new project (for
that, you need to create a new workbook), but you can use the Project Explorer to manage the
contents of the project.
Creating VBA Modules
All macros and procedures are stored within a VBA module. You can have more than one
module within a project, and that might even be necessary depending upon the complexity
of your project.
To create a new module, click Insert and then click Module, Class Module, or UserForm,
depending on the type of module you want to create. Figure 4-9 shows a recently created
blank module in a project. Once you’ve created the module, you can begin adding procedures
or designing the user form. Another option is to import a module from a text file. By clicking
File, Import File, you can select a text file that includes the code to be used in other modules
or user forms. The Visual Basic Editor creates a new module, so unless the code you import
is a complete procedure it won’t run until you add the Sub…End Sub notation.
Search JabSto ::




Custom Search