Communicating with Embedded Word Objects

When you embed a Word document in a Microsoft Excel worksheet, Microsoft Excel controls the object, and Word controls everything inside the object.

A linked object is an object that contains a reference pointer to its application. Data associated with a linked object isn't stored within the application that contains the object. If you change data in a linked application, the data will change in the original application as well.

An embedded object is an object that contains a "snapshot" of data existing at the time you embedded the object. Data associated with an embedded object is stored in the file in which the object is embedded. If you change data in an embedded object, the data in the original application doesn't change.

An OLE container application is an OLE-based application that can store embedded or linked objects provided by OLE object applications. An OLE object application is an application that exposes the OLE object.

Editing an Embedded Word Object

To edit a Word document embedded as an OLE object, you must activate it before you can refer to one of the top-level objects. The following example activates and edits a Word document, which is the first OLE object on Sheet1.


Dim wordobj As Object

Worksheets("sheet1").OLEObjects(1).Verb
Set wordobj = Worksheets("sheet1").OLEObjects(1).Object _     .Application.WordBasic
With wordobj
    .Insert "This is the new first line."
    .InsertPara
    .LineUp 1
    .EndOfLine 1
    .Bold
    .LineDown 1
End With

Note

Using the Verb method with no arguments, as demonstrated in the preceding example, is equivalent to using the Activate method. For information about the arguments you can use with the Verb method, see "Verb method" in Help.

Printing an Embedded Word Object

To print a Word document that's embedded on a Microsoft Excel sheet, first activate the embedded document, and then use the WordBasic FilePrint command. The following example activates, edits, and prints a Word document, which is the first OLE object on Sheet1.


Dim wordobj As Object

Worksheets("sheet1").OLEObjects(1).Verb
Set wordobj = Worksheets("sheet1").OLEObjects(1).Object _     .Application.WordBasic
With wordobj
    .Insert "Dear Mrs. Jones:"
    .InsertPara
    .FilePrint
    .FileClose
End With