Excel Macros
(Beginners Level)
In this first part you will learn how easy it is to record macros with the Macro Recorder and to create other macros in the Visual Basic Editor.
You will discover that:
- the Macro Recorder is not only a recorder but it is also the best teacher and an assistant that will be at your side for the future writing long sentences for you (without typos).
- the Visual Basic Editor is the most user friendly development environment that tells you immediately if there is a mistake in your sentences so that you don't have to wait at the end of your project to realize that something that you have written is not right.
- the Visual Basic Editor allows you to test your macros step by step while seeing them at work in your Excel spreadsheet.
Follow the Program
To communicate with colleagues and friends you have learned how to use your Email program. To communicate with Excel using VBA you will use the Visual Basic Editor (VBE). It is as easy as an Email program it is just a little different. You don't need to install the VBE you just need to open it by going to the menu bar of Excel "Tools/Macro/Visual Basic Editor".
But before we go there you have to set the security level of Excel to be allowed to create and use VBA procedures (macros). Again go to the menu bar "Tools/Macro/Security" and select the "Medium" level of security. From then on you will be asked if you want to enable the macros when you open a spreadsheet and if you don't know who it is coming from choose "Disable" as you would do with an Email from an unknown source.
So your first steps will consist in discovering the Visual Basic Editor, its menu bar and two useful toolbars (lesson 1-1).
There are three important windows in the VBE as there are in your Email program (address, subject and message). They are:
- the Project window where you will manage your spreadsheets (lesson 1-2)
- the Properties window where you will set the properties of the objects in your spreadsheets (lesson 1-3) and,
- the Code window where you will create and test your VBA procedures (lesson 1-4).
VBA is a very forgiving language and the VBE will tell you right away if you are writing the right things in the code window. You correct along the way making sure that your procedure will be executed and not stopped for simple typos.
Once you are familiar with the VBE you will learn how to develop small and simple VBA procedures (lesson 1-5) and how to test them step by step. You will even learn how to test your VBA procedures while seeing them at work in Excel on the same screen (lesson 1-6)...a powerful tool.
In lesson 1-7 you will discover your teacher and lifelong obedient assistant the Macro Recorder. Even as an expert you will use the Macro Recorder to write a lot of code hence avoiding the sometimes tedious keyboard dance when it is time to write long sentences or sentences that you don't use often. With the Macro Recorder you will also avoid typos that would ruin your creations.
In lesson 1-8 you will learn how to modify the macros written by the Macro Recorder who has some tendencies to forget the shortcuts. You will also learn how to modify your own macros while testing them. You correct you move back two lines and you go on testing....amazing.
Take a look at lesson1- 9 on security and protection. You will come back to it later.
Finally you will need to discover the events in lesson 1-10. For a VBA procedure to start there is to be an event like a click on a button. There are many events related to buttons, opening a workbook, leaving a sheet... For the moment learn how to attach a macro to a text box or to start it from the menu bar of Excel "Tools/Macro/Macros". Come back later for the other ones.
You are now ready not only to record macros but to create some and use them. Let's learn some vocabulary to talk with Excel.
Talking with Excel or writing a program in any language is called coding (you write code) and at the intermediate level that is what you will learn.
|