O'Reilly logo

Excel® 2007 VBA Programmer's Reference by Michael Alexander, Rob Bovey, Stephen Bullen, John Green

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 19. Interacting with Other Office Applications

The Office application programs Excel, Word, PowerPoint, Outlook, and Access all use the same VBA language. Once you understand VBA syntax in Excel, you know how to use VBA in all the other applications. Where these applications differ is in their object models.

One of the really nice things about the common VBA language is that all the Office applications are able to expose their objects to each other, and you can program interaction between all of the applications from any one of them. To work with Word objects from Excel, for example, you only need to establish a link to Word, and then you have access to its objects as if you were programming with VBA in Word itself.

This chapter explains how to create the link in a number of different ways, and presents some simple examples of programming the other application. In all cases, the code is written in Excel VBA, but it could easily be modified for any other Office application. The code is equally applicable to products outside Office that support the VBA language. These include other Microsoft products such as Visual Basic and SQL Server. There is also a growing list of non-Microsoft products that can be programmed in the same way.

Establishing the Connection

Once you have made a connection with an Office application, its objects are exposed for automation through a type library. There are two ways to establish such a connection: late binding and early binding. In either case, you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required