Читать книгу Excel VBA Programming For Dummies - Dick Kusleika - Страница 55

Looking at the parts of a module

Оглавление

In general, a VBA module can hold three types of code:

 Declarations: One or more information statements that you provide to VBA. For example, you can declare the data type for variables you plan to use or set some other module-wide options. Declarations are basically housekeeping statements. They aren’t actually executed.

 Sub procedures: A set of programming instructions that, when executed, performs some action.

 Function procedures: A set of programming instructions that returns a single value (similar in concept to a worksheet function, such as SUM).

A single VBA module can store any number of Sub procedures, Function procedures, and declarations. Well, there is a limit — about 64,000 characters per module. It’s unlikely you’ll even get close to reaching the 64,000-character limit. But if you did, the solution is simple: Just insert a new module.

How you organize a VBA module is completely up to you. Some people prefer to keep all their VBA code for an application in a single VBA module; others like to split the code into several modules. The best practice is to store related procedures in their own modules. For example, you might keep all the procedures that deal with importing and exporting data in a module called ImportExport, all the procedures that deal with formatting cells in a module called Formatting, and all the procedures that deal with printing in a module called Printing. Organizing your code in this manner makes it easier for you and others to understand and, if necessary, modify the code.

Excel VBA Programming For Dummies

Подняться наверх