Learn Computer Programming
Fast and Easy
with Visual Basic Tutorials

Beginning Programming with Visual Basic Tutorials

Throughout many years of experience in computer programming, I have found the easiest and best computer programming language to learn first was BASIC. BASIC stands for Beginners All-purpose Symbolic Instruction Code and has been around since the 1970’s. Since that time, it has evolved into a generation called Visual Basic.

What is Visual Basic?

Visual Basic, also known as VB, is a programming development environment created by Microsoft. It is used by programmers to develop Windows computer programs in the BASIC programming language.

Visual Basic can be programmed in its own environment or can be used with Microsoft Office (i.e. Microsoft Word, Excel, Outlook and Access) to create an even more powerful Office application. Visual Basic used with any of the Microsoft Office components is referred to as Visual Basic for Applications or VBA for short.

The Visual Basic language is the same in Excel, Word, Outlook and Access. The only difference is HOW its is used. For example, in Excel, VBA would be used to automate the manipulation of cells on a spreadsheet while VBA in Access would be used to automate data to and from a database.

Excel Visual Basic

For simplicity and usefulness, we'll explore the Excel VBA environment in the following Visual Basic tutorial. I have also chosen this because a great many people already own Excel and use it regularly. However, if you do not ready own Excel, you can download a Microsoft Office 60-day trial copy directly from Microsoft, which includes Excel 2007.

Although knowing how Excel works is not a prerequisite for learning how to program in this segment, it would be a good idea to find some free excel tutorials if you know nothing about Excel.

Excel Visual Basic Tutorial

Now, assuming you now have Excel installed on your computer, start Excel by double-clicking the Excel desktop icon which should look something like this:

Excel 2003 Icon or Excel 2007 Icon

Shortly thereafter, you should see a blank Excel grid, also known as a worksheet, as follows:

Excel Blank Sheet

As VBA runs "behind the scene" in Excel, the Visual Basic Editor can be accessed via the Macro item in the Tools drop-down menu as follows:

Start Excel VBA

This access method is for versions of Excel before 2007. For Excel 2007 and any other version of Excel, the Visual Basic Editor can be accessed by the short-cut key Alt+F11 (hold down the Alt key at the same time as the F11 key) as shown here:

ALT F11 Keyboard

Once you have done that, you should now be presented with the Visual Basic Editor which should look something like this:

Excel VBA Screen1

The Excel VBA Environment

As it is necessary that you understand a little about this environment, here is a brief description - enough to get you rolling.

Excel VBA Screen2 On the left side, you'll see a window called Project Explorer. It shows the different items (objects) you can program for. In Excel, this would show the current workbook (Excel file) and the different worksheets within that workbook.

In this example to the left, there is only one sheet in this workbook. If there were more worksheets, you would see all sheets listed.

For now, double-click on Sheet1 in your Project Explorer and a new window, called the code window, will be shown to the right as shown in the next image below.

Excel VBA Screen4

The code window is where you write your VBA Macro code. A Macro is a segment of VBA code identified by a name to perform a particular action.

Creating Your First Macro

OK, here we go. Type the following macro into the code window:

Sub MyFirstMacro()

     MsgBox "I am a VBA programmer!"

End Sub

Your code window should now look like this:

Excel VBA Screen5

This macro tells Excel to display a message box with the line "I am a VBA Programmer!". To run this macro, click the Run button as show:

Excel VBA Run Button

You should now see the following message box:

Excel Msg Box

Congratulations! You have just written your first computer program in Excel Visual Basic and have completed this tutorial! Very Well Done! :)

Return from Visual Basic Tutorials to Home Page

Learn to program