Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic
Write A Program!
5 - What Could Go Wrong?
Lesson 1
Write A Program

1 - Ready! Set! Go!

2 - Programmers, Start Your Recorders!

3 - Check Out The Macro

4 - Running The Macro

5 - What Could Go Wrong?

6 - OK ... Now What's Next?


Actually, quite a lot can go wrong even with a single statement program.

(Note: This section will be kept up to date as reports filter back on things that have tripped up students. So if you run into something that isn't covered here, let me know for the benefit of future generations of programmers.)

Where's My Program!

Students often save a program only to find that it seems to have disappeared when they open the Visual Basic Editor later on. This usually happens becuase they're looking in the wrong place. In Section 2, we learned that your program can be saved either in the Normal.dot document or in the current document. If you have more than one document open, you might have saved the macro in the 'other' one. In any case, you have to pay attention when you specify where the macro is to be saved.

There's no Visual Basic Help!

Later in the class, we make extensive use of Visual Basic Help to learn how to create code. But you might not see it in your installation of Word. Visual Basic Help is an optional part of the Microsoft Office installation. If it isn't on your computer, you may have to reconfigure your Office installation (Control Panel > Add or Remove Programs > Microsoft Office 2000 > 'Change' button) to add it. See THIS PAGE for instructions from Microsoft about how to do this.

My macro isn't activated!

Sergio wrote, "When I reached the part where you are supposed to run the program, a window appears and says that the Macro is not activated and that I should close the file and open it again in the activated mode."

This is the same problem that is discussed below in the heading, "There's a virus in my macro!" but this is the message most programmers will see. The solution is the same. Here are detailed instructions to solve the problem:

If your programs aren't running or if you see their taskbar icons blinking, it could mean that your security setting is preventing them from running. I keep my setting on "Medium" which allows me to decide whether a VBA program is allowed to execute or not.

If your security is set too high to allow your VBA programs to run (see the example of an error message below), you can follow these steps to change the security.

  1. On the Tools menu, point to Macro, and click Security. The Security dialog box appears.
  2. Click the Security tab.
  3. Click the Medium option. Try "Low" if you want to be double sure, but be aware that this leaves your system open to macros that you might not want to run so be sure to change it back again after experimenting.
  4. Quit and then restart the host application (*important* - the change isn't effective until you do this) and try running the macro again. The "disabled macros" message should not appear, and you should be able to run the macro normally.
Macro Security Error Message

Security and VBA is a huge topic with a lot of complications. One of the most important ways to control which VBA programs run is to sign programs with digital certificates so the application knows that they are from a Trusted Source. (A discussion of Digital Certificates and Trusted Sources would take much more space than we have here.)

In a business setting (or at home, if you run your computer in a businesslike way) an administrator can lock the security setting. For example, you could force the setting to High so that only programs in signed VBA projects can be run. An administrator can also control the trusted sources list to make sure only known trusted sources are on the list. Microsoft also added a new security method called AutomationSecurity in all Office XP applications to give programmers the ability to control security better. And finally, Microsoft Office 2000 and Office XP implements an anti-virus API (Application Programming Interface). If you open a document that contains macros and you have anti-virus software installed that implements the API, the anti-virus software scans the document for known viruses.

There's a virus in my macro!

This is probably the same problem that is discussed above See the discussion above in the heading, "My macro isn't activated!". See that section for a more complete explanation.

While viruses can be spread with VBA programs and it's wise to be very cautious, what is probably happening is that you have security set to 'Medium' (the default) and Word is only warning you that your document contains a VBA macro program - which it does: the program you wrote!

If there is any question, you can always open the document with macros disabled and then examine the macros to see what they are in the Visual Basic Editor.

Now that we've solved ALL of your problems, I'm sure you're eager to move ahead:

6 - OK ... Now What's Next?

Explore Visual Basic

By Category

About.com Special Features

Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.