Dealing With Complex Object Models

My first glimpse at Microsoft Excel's object model was very intimidating. There are over 100 objects available to the OLE Automation developer. Each of these objects has a myriad of properties and methods at your disposal. You don't have to memorize each of these properties and methods to be productive with Microsoft Excel; however, it helps to at least become familiar with what's there.

A great way to learn how to use these properties and methods is through Microsoft Visual Basic® for Applications, Microsoft Excel's built-in macro language. You may be wondering how learning another programming language will help you to understand how to use Microsoft Excel's object model from FoxPro. The answer is in knowing how Visual Basic for Applications communicates with it's host environment, Microsoft Excel. Visual Basic for Applications uses the same objects, properties, and methods that are available to FoxPro through OLE Automation. In fact, Visual Basic for Applications itself uses OLE Automation to communicate with Microsoft Excel. Knowing this, we can use Microsoft Excel's built in macro recorder to record the functionality that we are trying to model. The macro recorder generates Microsoft Visual Basic code, which you can examine to see how various objects are being used. Granted, not every construct in Microsoft Visual Basic is directly portable to FoxPro, but Microsoft Visual Basic interacts with Microsoft Excel much in the same way that FoxPro does, and the syntax when dealing with Microsoft Excel objects is almost identical. In many cases you will discover new objects or techniques that you previously didn't know existed.

Another great way to become familiar with an application's objects is through the command window, from which you can interactively create objects, set object properties, call object methods, and just plain have fun with OLE Automation.