1. Computing

Using Office Apps Together in VBA

It's not easy, but it is possible

From , former About.com Guide

Updated January 08, 2007

"Trisped" asked, "I can't figure out how to make VBA in Word access an embedded Excel spreadsheet."

That's because it's just not very easy to do.

What we're dealing with here is "old style" OLE (Object Linking and Embedding) technology. In 1996, Microsoft renamed the OLE 2.0 technology to ActiveX, but it's still OLE. I suspect that this technology will continue to be with us for quite a while since it's still supported in the new Office 2007!

The old trick of recording a macro to see how to write the code isn't much help here. You'll discover that Word simply refuses to capture the critical statements that show you how to do this.

The general approach to doing this is to create an object for the second Office product (in our example below, that's Excel) inside the VBA macro code for the first one (Word, in our example). But there are a variety of ways that it can be done and I'll show several of them. Depending on which approach you use, you can then use the properties and methods for the object that you create to actually work with the second product.

If you're using a different Office app (but one that still supports VBA), the ideas here still work but the objects will be different. You just have to search the documentation to figure out what they are.

First, lets set up the situation. Open Excel and add some content to a few cells in the first spreadsheet just to give yourself something to work with. Close and save the workbook, making a note of the name and location.

Now, open Word and select Insert > Object.... Select the Create From File tab and browse to the workbook you just created.

Here's the first major decision that you need to make.

Note the checkbox labeled Link to File. This checkbox determines whether the spreadsheet is embedded or linked (remember, OLE is Object Linking and Embedding). The code you use to work with the spreadsheet in word depends on which way it was done.

The next page shows you the code ...

©2013 About.com. All rights reserved.