- Computers & Software»
- Computer Science & Programming»
- Programming Languages
VBA: Where do I put the code?
If you have completed my previous module you have recorded several macros with the macro recorder. You are likely now eagerly awaiting the opportunity to view your first code.
Opening the Visual Basic Window in Excel 2003 & 2010
The VBA environment is pretty much the same in Excel 2003 and Excel 2010. In the video below I show give you a short tour of VBA in Excel 2010, don't worry if you have 2003 you will be able to follow along easily.
Exploring the VBA Environment
A Project is the composition of all VBA elements contained in a workbook.
A Module is a place holder within a workbook for your code.
You will notice when you recorded the macro excel created a new module for the code called "Module 1".
When first viewing your code. You will notice three things:
- Macros begin with code Sub (this stands for subroutine).
- Sub is followed by the name of the macro.
- Macros end with the statement End Sub.
One Last Thing to Note
In your recorded macros you will notice green text in the code window. These are comments. You can create a comment line by starting it with an apostrophe.
An apostrophe tells VBA the line doesn't contain code and is only informational.
As you begin to create more complicated macros, comments will become a necessity for remembering the purpose of each part of your code.
Ready to Proceed?
In the next module, we will learn to select to select and enter text in cells within Excel and from VBA. Click here when you are ready to proceed.