Code Window
This displays the code associated with the item selected in the Project Explorer window.
Also sometimes referred to as a Module window.
You can even just double click the item in the Project Explorer window.
Displaying the Code Window
To display the code select the item in the Project Explorer window and either choose (View > Code) or you can alternatively use the shortcut key (F7).
A code module will normally contain more than one procedure or function.
The IDE offers you a choice of whether to display the procedures one at a time (procedure view) or all at one (full module view).
You can change the views by clicking on the small buttons in the lower-left corner of the code window. Full Module view is the default.
You can minimise, maximise, hide and rearrange your code windows.
Use the Code window to write, display, and edit Visual Basic code.
You can open as many Code windows as you have modules, so you can easily view the code in different forms or modules, and copy and paste between them.
You can open a Code window from:
The Project window, by selecting a form or module, and choosing the View Code button.
A UserForm window, by double-clicking a control or form, choosing Code from the View menu, or pressing F7.
The Recycle Bin.
Window Elements
Object Box
Displays the name of the selected object. Click the arrow to the right of the list box to display a list of all objects associated with the form.
Procedures/Events Box
Lists all the events recognized by Visual Basic for a form or control displayed in the Object box. When you select an event, the event procedure associated with that event name is displayed in the Code window.
If (General) is displayed in the Object box, the Procedure box lists any declarations and all of the general procedures that have been created for the form. If you are editing module code, the Procedure box lists all of the general procedures in the module. In either case, the procedure you select in the Procedure box is displayed in the Code window.
All the procedures in a module appear in a single, scrollable list that is sorted alphabetically by name. Selecting a procedure using the drop down list boxes at the top of the Code window moves the cursor to the first line of code in the procedure you select.
Macros can also be created by typing the commands directly into a code window.
This is often faster than using the macro recorder assuming you are familiar with the corresponding object model.
Code windows can hold four different types of code
1) Subroutines - a set of instructions that performs a particular task
2) Functions - a set of instructions that performs a particular task and then returns a value or an array.
3) Properties - these are used in class modules
4) Declarations - this is used to declare variables that can be used and referenced from anywhere in the module (or project).
A single VBA module can store any number of any of the above and how these are organised is up to you.
Full Module View
icon - Full Module View Icon - Displays the entire code in the module.
This is the default.
horizontal lines separating the procedures and functions.
Procedure View
This can be controlled from (Tools > Options)(Editor Tab, "Default to Full Module View")
icon - Procedure View Icon - Displays the selected procedure. Only one procedure at a time is displayed in the Code window.
There are multiple levels of Undo and Redo so don't worry if you ever remove the wrong instruction or procedure. You can click the Undo button (Ctrl + "Z") repeatedly.
After undoing, you can press F4 to redo changes that were previously undone.
Force Intellisense
When no listbox is displayed you can press (Ctrl + Spacebar) to complete the input with the given keyword (or variable name).
If there is more than one option then the listbox automatically appears.
Once the listbox has been displayed you can select the desired input with the cursor key
The Tab key completes the selection.
With ESC you can avoid having to select from the listbox and can complete the input manually.
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext