Summary

Object linking and embedding is a great way to use the strengths of various Microsoft Office applications where it makes sense, yet still retain the ability to bring everything together into a unified document. A document that contains components created using different applications is referred to as a compound document.

Object linking and embedding is enabled thanks to a powerful architecture referred to as the Component Object Model (COM). Over the years, Microsoft has kept everyone confused by naming, renaming, and shifting definitions of various COM-related technologies—especially the functionality related to object linking and embedding (OLE).

Although OLE is helpful in many situations, you'll undoubtedly run into situations where OLE doesn't quite cut it. In these instances, you may need to employ a concept commonly know of as automation. Automation involves controlling one application using code that "lives" within a different application. For example, you could conceivably create a Microsoft Word application implemented entirely in VBA that runs from Excel. Not that you would actually want to do this. When developing solutions involving multiple Microsoft Office applications, generally one of the applications (Access, Excel, Word, etc.) will emerge as the dominant application for the solution and usually the dominant application contains the code that implements the solution.

One key concept of automation is the concept of binding. Binding refers to the process of "introducing" an external class library (such as Word) to the environment in which your code runs. There are two classifications of binding. Early-bound objects are objects that are bound during development by setting a reference to the object's class library in the VBE. Late-bound objects are objects that are bound at run-time by explicitly creating an instance of the object using CreateObject. For performance reasons, early binding is the most commonly used way to bind external class libraries to VBA projects.

OLE and automation are great for getting at data embedded in other Microsoft Office applications (or other applications that support OLE and automation), however, the world is much, much bigger than the data embedded in these applications. To explore other data in the universe you need to find a common denominator. The common denominator has historically been the simple text file. In the next chapter, I cover issues related to working with and creating text files.

0 0

Post a comment