This article is the third page of Lesson one in the About Visual Basic tutorial "VB Programming for Non-Programmers!". Sign up for the entire course at ... this signup page. The article is continued from the previous page where we recorded a VBA macro in Word. In this page, we find out what is in the macro.
Open Word again and select the AboutVB1.doc file that you saved in the previous lesson. To see what the Macro Recorder has created (as well as to do most other things that involve VBA), you need to find and open the Visual Basic Editor. You can do this using the menu commands "Tools > Macro > Visual Basic Editor" and then selecting "NewMacros" in the Project Explorer window.
First, notice the left hand window. This is called the Project Explorer and it groups together the high level objects (later lessons deal with these objects in more detail) that are part of your Visual Basic project.
When the Macro Recorder was started, you had a choice of the Normal template or the current document as a location for your macro. If you selected Normal, then the NewMacros module will be part of the Normal branch of the Project Explorer display. (You were supposed to select the current document.) The Project Explorer in the VBA Editor is shown when you click Here. Click the "Back" button in your browser to return.
The program source for the object selected in the Project Explorer is displayed in the right hand window. If you don't see any source, check to make sure NewMacros is selected in the Project Explorer. There is an alternative view of Project Explorer called Folder view (at left). I think this one is more confusing. If this one is displayed on your computer, click the Folder View Toggle button to switch back. The Folder view of Project Explorer is shown when you click Here. Click the "Back" button in your browser to return.
Every Visual Basic program must be in some kind of file 'container'. In the case of Word VBA macros, that container is the ('.doc') Word document. Word VBA programs can't run without Word and you can't create standalone ('.exe') Visual Basic programs like you can with Visual Basic 6. But that still leaves a whole world of things you cando.
Your first program is certainly short and sweet, but it will serve to introduce the major features of VBA and the Visual Basic Editor.
The program source will normally consist of a series of subroutines. When you graduate to more advanced programming, you'll discover that other things can be part of the source too.
This particular subroutine is named AboutVB1 . The subroutine header must be paired with an "End Sub" at the bottom. The parenthesis can hold a parameter list consisting of values being passed to the subroutine. Nothing is being passed here, but they have to be there in the "Sub" statement anyway. Later, when we run the macro, we will look for the name AboutVB1 .
There is only one actual program statement in the subroutine:
Selection.TypeText Text:="Hello World!"
But this statement contains the big three:
- an object
- a method
- a property
The statement actually adds the text "Hello World." to the contents of the current document.
The next task is to run our program a few times. Just like buying a car, it's a good idea to drive it around for a while until it feels a little bit comfortable. We do that in the fourth page of this series. 4 - Running The Macro

