Balls("Soccer").Kick Left, Hard, High

This throws a monkey wrench into our understanding. Without the colon-equals, it is not obvious that we have parameters. Unless you know the parameter order, you might not understand what is being said. It is pretty easy with Left, Hard, and High, but when you have parameters like the following:

WordArt.Add Left:=10, Top:=20, Width:=100, Height:=200 It gets really confusing to see: WordArt.Add 10, 20, 100, 200

The preceding is valid code, but unless you know that the default order of the parameters for this Add method is Left, Top, Width, Height, this code will not make sense. The default order for any particular method is the order of the parameters as shown in the help topic for that method.

To make life more confusing, you are allowed to start specifying parameters in their default order without naming them, and then all of a sudden switch to naming parameters when you hit one that does not match the default order. If you wanted to kick the ball to the left and high, but do not care about the force (you were willing to accept the default force), then the following two statements are equivalent:

Balls("Soccer").Kick Direction:=Left, Elevation:=High

Balls("Soccer").Kick Left, Elevation:=High

As soon as you start naming parameters, then they have to be named for the remainder of that line of code.

Some methods simply act on their own. To simulate pressing the F9 key, you would use this code:


Other methods perform an action and create something. For example, you can add a worksheet with

Worksheets.Add Before:=Worksheets(1)

However, because Worksheets.Add actually creates a new object, you can assign the results of this method to a variable. In this case, you must surround the parameters with parentheses:

Set MyWorksheet = Worksheets.Add(Before:=Worksheets(1))

One final bit of grammar is necessary. Adjectives. Adjectives describe a noun. Properties describe an object. We are all Excel fans here, so I am going to switch from the soccer analogy to an Excel analogy midstream. There is an object to describe the active cell. Luckily for us, it has the very intuitive name of


Let's say that we want to change the color of the active cell to yellow. There is a property called Interior.Colorlndex for a cell. It uses a complex series of codes, but you can turn a cell to yellow by using this code:

ActiveCell.Interior.Colorlndex = 6

0 0

Post a comment