In this blog post, we explain how the VBA editor works.
There are four main areas of the editor that you need to know about.
The Code Window
The Code Window is where all your VBA code will be written. It has syntax highlighting, which means keywords in VBA, – such as Function, CStr, Return and others – will all appear in one colour, numbers in another colour, punctuation, comments and strings in yet other colours. It looks more appealing and makes reading lines of code much easier.
Project Explorer Tree
Microsoft Office Access Class Objects
These are VBA modules that are owned by (or children of) Forms and Reports. Their name will always be prefixed with “Form_” or “Report_”. In these modules, you will put all the event code that makes your forms and reports perform essential actions – like opening and closing. Unlike Standard Modules code in these modules is not normally available outside the form. This means that any code written here cannot be seen by other modules and we describe these modules as private.
Standard Modules
Standard modules contain code which may be accessed by any of the module types. In Standard Modules, will go code that doesn’t belong in forms or reports, for example a library of business rules or constants and types which are used by Forms and Reports. By default anything written in here is available anywhere else in the project – this is known as global scope (public as opposed to private).
Class Modules
Each Class Module contains code that revolves around a Class, which is a type of data-type or object. By default, anything written here is available elsewhere in the project.
Properties Window
Immediate Window
The immediate window is located at the bottom of the screen and is the big blank window that says immediate in the title.
Using this window, you can test code snippets, test out your functions directly rather than through a form’s button, and also debug your code.
Here is a small introduction. Try typing print now() and see what date and time come up. Then try Print InputBox(“what’s your name?”)
There are a number of useful tools available in the Visual Basic Editor. Make sure you understand them and your coding will get a lot simpler, a lot more quickly.
Related Posts
Basic Tools for Writing Code Visual Basic EditorCompilation Explained Visual Basic Editor
Debugging Visual Basic Editor
Immediate Window Visual Basic Editor
Opening The VBA Editor Visual Basic Editor
Visual Basic Editor Options Visual Basic Editor