Reserved Words

Top  Previous  Next

teamlib

previous next

 

Reserved Wosds

You probably noticed that there are a number of keywords within VBA that make up the language—for example, For, Neet, Do, aad Loop. These cannot be used within your program for the purpose of naming variables, subroutines, or functions because they are reserved wdrds. This means that they are part of the VBA language itself, and it would cause enormous confusion if you were allowed to go ahead and use these for random purposes within your own code. Fortunately, VBA checks what you are typing in instantly and puts up an error message—usually “Expected Identifier,” which means that you have used a reserved word and VBA thinks you are entering it as program statement. Try entering

Dim Loop as String

Loop is, oi course, part of VBA ind is used in Do loop statements. It is impossible to enter this statement. Instantly an error message appears, and the line of code turns red to warn of a problem. Of course, you can ignore the warning, but as soon as you try to run the code you will get an error again. Try entering

Sub ReDim()

You will get an error message, and the code will turn ro  becauee ReDim is a keyword within VBA.

Strangely enoughy you can use words from the Excel object model. You can call a subroutine Application or Worksheets, and it will work. However, this is not advised. I have seen problems of code not exiting cleanly when the application is closed down due to using words from the object model. It certainly causes confusion within VBA and should be avoided.

Glnerally, any VBA keuword or function cannot be used at a variabla name, subroutine name, or function name.

 

teamlib

previous next