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.
You can drag selected text to:
- A different location in the current Code window.
- Another Code window.
- The Immediate and Watch windows.
- The Recycle Bin.
|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 by 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.
|Split bar||Dragging this bar down splits the Code window into two horizontal panes, each of which scrolls separately. You can then view different parts of your code at the same time. The information that appears in the Object box and Procedures/Events box applies to the code in the pane that has the focus. Dragging the bar to the top or the bottom of the window or double-clicking the bar closes a pane.|
|Margin Indicator bar||A gray area on the left side of the Code window where margin indicators are displayed.|
|Procedure View icon||Displays the selected procedure. Only one procedure at a time is displayed in the Code window.|
|Full Module View icon||Displays the entire code in the module.|
Use the following shortcut keys to access commands in the Code window.
|View Code window||F7|
|View Object Browser||F2|
|Next procedure||CTRL+DOWN ARROW|
|Previous procedure||CTRL+UP ARROW|
|Shift one screen down||CTRL+PAGE DOWN|
|Shift one screen up||CTRL+PAGE UP|
|Go to last position||CTRL+SHIFT+F2|
|Beginning of module||CTRL+HOME|
|End of module||CTRL+END|
|Move one word to right||CTRL+RIGHT ARROW|
|Move one word to left||CTRL+LEFT ARROW|
|Move to end of line||END|
|Move to beginning of line||HOME|
|Delete current line||CTRL+Y|
|Delete to end of word||CTRL+DELETE|
|Clear all breakpoints||CTRL+SHIFT+F9|
|View shortcut menu||SHIFT+F10|
Code window editing keys
Use these key combinations to edit code in the Code window.
|CTRL+C||Copy the selected text to the Clipboard.|
|CTRL+X||Cut the selected text to the Clipboard.|
|DELETE or DEL||Delete the selected text without placing it on the Clipboard.|
|CTRL+V||Paste the Clipboard contents at the insertion point.|
|CTRL+Z||Undo the last editing action in the current line.|
|CTRL+Y||Cut the current line to the Clipboard.|
|CTRL+DELETE||Delete to the end of the word.|
|CTRL+BACKSPACE||Delete to the beginning of the word.|
|SHIFT+F4||Find Next: repeat text search down through your code. If no text search has been done, the Find dialog box is displayed.|
|SHIFT+F3||Find Previous: repeat text search up through your code. If no text search has been done, the Find dialog box is displayed.|
Code window general use keys
Use these key combinations in the Code window.
|F1||Get context-sensitive Help on functions, statements, methods, properties, or events.|
|F2||Display the Object Browser.|
|F9||Set or remove a breakpoint.|
|CTRL+SHIFT+F9||Clear all breakpoints.|
|F5||Run a Sub/UserForm or macro.|
|F8||Execute code one line at a time (single step).|
|SHIFT+F8||Execute code one procedure at a time (procedure step).|
|CTRL+BREAK||Stop running a Visual Basic application.|
|HOME||Move the cursor to the beginning of text in a line.|
|END||Move the cursor to the end of text in a line.|
|Double-click on the split bar||Delete the split bar.|
|SHIFT+F10||View shortcut menu.|
|ALT+F5||Runs the error handler code or returns the error to the calling procedure. Does not affect the setting for error trapping on the General tab of the Options dialog box.|
|ALT+F8||Steps into the error handler or returns the error to the calling procedure. Does not affect the setting for error trapping on the General tab of the Options dialog box.|
|CTRL+J||Turn on ListProperties/Methods.|
|CTRL+SHIFT+J||Turn on List Constants.|
|CTRL+I||Turn on Quick Info.|
|CTRL+SHIFT+I||Turn on Parameter Info.|
|CTRL+SPACEBAR||Turn on Complete Word.|
Code window menu shortcut keys
Use these key combinations for menu shortcuts in the Code window.
|DEL or DELETE||Delete|
|CTRL+F8||Run To Cursor|
|CTRL+SHIFT+F9||Clear All Breakpoints|
|F5||Run Sub/Form or Run Macro|
Code window navigation keys
Use these key combinations to navigate in the Code window.
|CTRL+F2||Move the insertion point into the Object box.|
|SHIFT+F2||Go to the definition of the selected procedure.|
|CTRL+DOWN ARROW||Display the next procedure.|
|CTRL+UP ARROW||Display the previous procedure.|
|PAGE DOWN||Page down through the procedures in your code.|
|PAGE UP||Page up through the procedures in your code.|
|CTRL+SHIFT+F2||Go back to the last position in your code.|
|CTRL+HOME||Go to the beginning of the module.|
|CTRL+END||Go to the end of the module.|
|CTRL+RIGHT ARROW||Go one word to the right.|
|CTRL+LEFT ARROW||Go one word to the left.|
|END||Go to the end of the line.|
|HOME||Go to the beginning of the line.|
|CTRL+PAGE DOWN||Go to the bottom of the current procedure.|
|CTRL+PAGE UP||Go to the top of the current procedure.|
|F6||Switch between Code window panes (when the window is split).|
Code window and Object Browser icons
The Object Browser window and Code window contain many icons that represent classes and members. The following is a list of icons and what they represent.
|This icon...||Represents a...|
|Built-in keywords and types|