Microsoft Office Tutorials and References
In Depth Information
Working with Code Windows
Minimizing and maximizing windows
Depending on how many workbooks and add-ins are open, the VBE can have lots of code
windows, and things can get a bit confusing. Code windows are much like worksheet windows in
Excel. You can minimize them, maximize them, rearrange them, and so on. Most people find it
most efficient to maximize the Code window that they’re working in. Doing so enables you to see
more code and keeps you from getting distracted. To maximize a Code window, click the
maximize button in its title bar or just double-click its title bar. To restore a Code window (make it
nonmaximized), click the Restore button (below the Application title bar).
Sometimes, you may want to have two or more Code windows visible. For example, you might
want to compare the code in two modules or perhaps copy code from one module to another. To
view two or more Code windows at once, make sure that the active code window isn’t
maximized. Then drag and resize the windows that you want to view.
Minimizing a code window gets it out of the way. You can also click the Close button in a Code
window’s title bar to close the window completely. To open it again, just double-click the
appropriate object in the Project Explorer window.
The VBE doesn’t have a menu command to close a workbook. You must reactivate Excel and
close it from there. You can, however, use the Immediate window to close a workbook or an
addin. Just activate the Immediate window (press Ctrl+G if it’s not visible), type a VBA statement like
the one that follows, and press Enter:
Workbooks(“myaddin.xlam”).Close
As you’ll see, this statement executes the Close method of the Workbook object, which closes
a workbook. In this case, the workbook happens to be an add-in.
Storing VBA code
In general, a code window can hold four types of code:
h Sub procedures: A procedure is a set of instructions that performs some action.
h Function procedures: A function is a set of instructions that returns a single value or an
array (similar in concept to a worksheet function, such as SUM).
h Property procedures: These are special procedures used in class modules.
h Declarations: A declaration is information about a variable that you provide to VBA. For
example, you can declare the data type for variables you plan to use.
A single VBA module can store any number of Sub procedures, Function procedures, and
declarations. 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 up the code into
several different modules.
 
Search JabSto ::




Custom Search