Inserting an Object from Another Application


Using the Office or Windows Clipboard to copy data from one application to another is simple, but both methods suffer from three major problems. First, if the data gets changed in the original application, the document containing the copy will become out of date. This has two consequences:

  • If you know that the data needs to be updated, you have to repeat the whole copy-and-paste procedure to get the latest version of the data.

  • If you don't know that the data needs to be updated (for example, if someone else changes the original data without telling you), you'll be stuck with an old version of the info.

Second, what if you want to make changes to the copied data? You might be able to edit the data directly (if it's just text, for example), but more often than not, you'll need to fire up the original application, change the data there, and then copy the data again. However, problems can arise if you're not sure which application to use or if you're not sure which file contains the original data.

Third, copying data between documents is often wasteful because you end up with multiple copies of the same data. You could cut the data from the original application and then paste it, but then there would be no easy way to edit the data using the original application.

It would be nice if you didn't have to worry about the updating of your shared data. It would be nice if there were a system that would accomplish three goals:

  • If the data changes in the original application, it updates the copied data automatically.

  • If you want to edit the copied data, it makes it easy to find both the original application and the original data file.

  • It lets you store non-native data inside a document without having to maintain separate documents for the original data.

Happily, the twin technologies of linking and embedding meet all three goals and add a few extra conveniences to the mix for good measure.

Understanding Compound Documents

A compound document is a document that contains, along with its native data, one or more objects that were created using other applications. The key point is that the compound document's native data and its objects can have entirely different data formats. For example, a Word document can include an Excel range object or a sound clip object. The container application doesn't need to know a thing about these alien data formats, either. All it has to know is the name of the server application that created the data and how to display the data. All this information (and more) is included free of charge as part of the object, so it's readily available to the container application.

You create a compound document by either linking objects to the document or embedding objects in the document. The next three sections explain linking and embedding in more depth.

Linking and Embedding in Access

You can't link or embed objects in just any field of an Access table. Instead, you need to create a separate field that's configured for the OLE Object data type. After that's done, you can insert linked or embedded objects in that field.


Understanding Linking

Linking is one of the methods you can use to insert an object into a file from a container application and thus create a compound document. In this case, the object includes only the following information:

  • The Registry key needed to invoke the object's server application.

  • A metafile that contains instructions on how to display the object. These instructions generate the primitives (lines, circles, arcs, and so on) that create an image of the object. So the container application doesn't have to know a thing about the object itself; it just follows the metafile's instructions blindly, and a perfect replica of the object's image appears.

  • A pointer to the server application file (the source document) that contains the original data.

Linking brings many advantages to the table, but three are most relevant to our purposes. First, the link lets the container application check the source document for changes. If it finds that the data has been modified, it can use the link to update the object automatically. For example, suppose you insert a linked Excel worksheet object into a Word document. If you revise some of the numbers in the worksheet sometime down the road, the object inside the document is automatically updated to reflect the new numbers. However, this updating is automatic only under certain conditions:

  • If the container application is running and has the compound document open, the update is automatic.

  • If the compound document isn't open when the data is changed, the object gets updated automatically the next time you open the compound document.

  • Most applications let you disable automatic updating either for individual documents or for the application as a whole. In this case, you need to perform the updates manually. (I'll show you how this is done later in this chapter.)

Second, because the object "knows" where to find both the server application and the source document, you can edit the object from within the container application. In most cases, double-clicking the object invokes the server and loads the appropriate source file. You can then edit the original data and exit the server application, and your object is, once again, updated automatically.

Third, because the source data exists in a separate file, you can easily reuse the data in other compound documents, and you can edit the data directly from within the server application.

Understanding Embedding

One of the problems associated with linking is that if you distribute the compound document, you also have to distribute the source document. Embedding solves this problem by inserting an object not only with the server's Registry information and the metafile for displaying the object, but also with the object's data. This way, everything you need to display and work with the object exists within the object itself. There's no need for a separate source file, so you can distribute the compound document knowing that the recipient will receive the data intact.

In fact, embedding lets you create server objects from within the container application. If you're working with Word, for example, you can insert a new Excel worksheet object into your document. Windows will start Excel so that you can create the new object, but when you exit Excel, the object will exist only within the Word compound document. There will be no separate Excel file.

Note that many applications can operate only as servers. This means that they aren't standalone applications and therefore have no way to create files on their own. They exist only to create objects for compound documents. Microsoft Office ships with several examples of these applications, including WordArt and Microsoft Graph.

Should You Link or Embed?

Perhaps the most confusing aspect of all this is determining whether you should link your objects or embed them. As you've seen, the major difference between linking and embedding is that a linked object stores only a pointer to its data, whereas an embedded object stores its own data internally.

With this in mind, you should link your objects if any of the following situations apply:

  • You want to keep your compound documents small. The information stored in a linked objectthe pointers to the server and source document, and the metafileconsume only about 1.5KB, so very little overhead is associated with linking.

  • You need to keep the source file as a separate document in case you want to make changes to it later, or in case you need it for other compound documents. You're free to link an object to as many container files as you like. If you think you'll be using the source data in different places, you should link it to maintain a separate file.

  • You won't be sending the compound document via email or floppy disk. Again, OLE expects the linked source data to appear in a specific place. If you send the compound document to someone else, he or she might not have the proper source file to maintain the link.

Similarly, you should embed your objects if any of the following situations apply:

  • You don't care how big your compound documents get. Embedding works best in situations in which you have lots of hard disk space and lots of memory.

  • You don't need to keep the source file as a separate document. If you need to use the source data only once, embedding it means you can get rid of the source file (or never have to create one in the first place) and reduce the clutter on your hard disk.

  • You'll be sending the compound documents and you want to make sure the object arrives intact. If you send a file containing an embedded object, the other person will see the data complete and unaltered. If the recipient wants to edit the object, however, he or she will need to have the server application installed.

Linking an Object

If you have data you'd like to share between applications, and you think that linking is the best way to go, Windows gives you two methods: linking via the Clipboard and inserting a linked file. The next two sections discuss each method. Then I'll show you how to work with and maintain your links.

Linking via the Clipboard

After you've placed the data on the Clipboard, switch to the container application and position the cursor where you want the data to be pasted. Now select Edit, Paste Special to display the Paste Special dialog box, shown in Figure 6.3.

Figure 6.3. Use the Paste Special dialog box to paste Clipboard data as a linked object.


The As box lists the various formats available for the data, but you can ignore most of them. To establish a link between the container and the server, you need to do two things:

  • Activate the Paste Link option.

  • Select the "Object" format (for example, Microsoft Office Excel Worksheet Object).

If you'd like the data to appear as an icon in the container document, activate the Display as Icon check box. When you're ready, click OK to paste the linked object into the container. Figure 6.4 shows an Excel range pasted normally and as an icon.

Figure 6.4. A linked Excel worksheet object displayed normally and as an icon.


Inserting a File as a Linked Object

Instead of pasting part of a document as a linked object, you might prefer to insert an entire file as a linked object. For example, if you insert a linked Excel workbook into a Word document, the container object will reflect any changes made to the original file, including data added or removed, global formatting adjustments, and so on. (Note, however, that in this case only the first worksheet is inserted.)

Also, in certain situations you have no choice but to insert a file. For example, you can't insert part of a bitmap as a linked object; instead, you have to insert the entire file.

Here are the basic steps to follow to insert a file as a linked object:

1.

In the container application, position the cursor where you want the file inserted.

2.

Select Insert, Object to display the Object dialog box.

3.

Select the Create from File tab, shown in Figure 6.5. (In some applicationssuch as PowerPoint and Accessyou activate the Create from File option, instead.)

Figure 6.5. Use the Create from File tab to insert a file object in the container.


4.

Enter the filename of the file you want to link. You can also click the Browse button to choose the file from a dialog box.

5.

Activate the Link to File check box. (In PowerPoint and Access, activate the Link check box, instead.)

6.

If you want the linked file to appear as an icon, activate the Display as Icon check box.

7.

Click OK to insert the linked file object.

Managing Links

All container applications that support object linking also give you some kind of method to manage document links. This involves updating a link so that the container displays the most recent changes, changing a link's source, determining how links are updated in the container, and breaking links you no longer need to maintain.

In most container applications, you manage links by selecting Edit, Links to display the Links dialog box, which should be similar to the one shown in Figure 6.6 (this is the Links dialog box from Word).

Figure 6.6. Container applications that support object linking have a Links dialog box that you can use to maintain the links.


Following is a rundown of the basic link management chores you can perform:

  • Changing the link update methodBy default, links are updated automatically. In other words, if both the source and the container are open, whenever the source data changes, the data in the container also changes. If you would prefer to update the container document by hand, select the link and activate the Manual option.

  • Updating the linkIf you've set a link to Manual, or if the server document isn't open, you can make sure a link contains the latest information by selecting it and clicking the Update Now button.

  • Changing the link sourceIf you move the source document, you might need to modify the link so that it points to the new location. You can do this by selecting the appropriate link and clicking the Change Source button.

  • Breaking a linkIf you no longer want to maintain a link between the source and the container, you can break the link. This will leave the data intact, but changes made to the original data will no longer be reflected in the container. To break a link, highlight it and click the Break Link button.

Embedding an Object

If you prefer to embed an object instead of linking it, Windows gives you three methods to choose from (depending on the server application): the Clipboard, inserting a new embedded object, and inserting an embedded file.

Embedding via the Clipboard

To embed data that's been placed on the Clipboard, switch to the container application, position the cursor where you want the data to be pasted, and select Edit, Paste Special. In the Paste Special dialog box that appears, you embed the data by doing two things:

  • Activate the Paste option.

  • Select the Object format (for example, Microsoft Office Excel Worksheet Object).

Also, if you'd like the data to appear as an icon in the container document, activate the Display as Icon check box. When you're ready, click OK to embed the object in the container.

Inserting a New Embedded Object

If the object you want to embed doesn't exist, and you don't need to create a separate file, Windows lets you insert the new object directly into the container application. Here's how it works:

1.

In the container application, move the cursor to where you want the new object to appear.

2.

Select Insert, Object to display the Object dialog box as shown in Figure 6.7. Make sure the Create New tab is selected.

Figure 6.7. In the Object dialog box, use the Create New tab to select the type of embedded object you want to create.


3.

The Object Type list displays all the available objects on your system. Select the type of object you want to create.

4.

Click OK. Windows starts the server application for the object type you selected. The server will appear either in place or in a separate window.

5.

Create the object you want to embed.

6.

Exit the server application. If you were working with the server using visual editing, click outside the object. Otherwise, select File, Exit and Return to document, where document is the name of the active document in the container application.

Inserting an Embedded File

You can insert an entire existing file (in contrast to an object within a file) as an embedded object. This is useful if you want to make changes to the file from within the container without disturbing the original. Follow these steps:

1.

In the container document, position the cursor where you want to embed the object.

2.

Select Insert, Object to display the Object dialog box.

3.

Select the Create from File tab. (In some applicationssuch as PowerPoint and Accessyou activate the Create from File option instead.)

4.

Enter the filename of the file you want to link. You can also click the Browse button to choose the file from a dialog box.

5.

If you want the embedded file to appear as an icon, activate the Display as Icon check box.

6.

Click OK to insert the embedded file object.

Editing a Linked or Embedded Object

If you need to make some changes to a linked or embedded object, you can use the container application to launch the server application and load the object automatically. (Remember, too, that for a linked object, you can always run the server application and work with the object directly.) How you do this depends on the application, but here are a few methods that work for most containers applications:

  • Double-click the object.

  • Select the object, pull down the Edit menu, and then select either Linked ObjectType Object (for a linked object) or ObjectType Object (for an embedded object). In both cases, ObjectType is the type of object you selected (for example, Bitmap Image or Worksheet). In the menu that appears, select Edit. If the server application supports visual editing, this will launch the object in place.

  • Select the object, pull down the Edit menu, and then select either the Linked ObjectType Object command (for a linked object) or the ObjectType Object command (for an embedded object). In the cascade menu that appears, select Open. For servers that support the Open verb, this will launch the object in a separate window.

  • Right-click the object, select either Linked ObjectType Object or ObjectType Object, and select either Edit or Open.

Edit Isn't Always the Default

Sometimes, when you double-click an object (such as a PowerPoint presentation or a sound file), Windows will play the object instead of editing it. In this case, you can edit the object only by using the appropriate Edit command.




Tricks of the Microsoft Office Gurus
Tricks of the Microsoft Office Gurus
ISBN: 0789733692
EAN: 2147483647
Year: 2003
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net