22.2. Embedding and Linking Objects
Embedding and linking are two tools that let you build compound documents , which contain content from two or more applications. For example, you might have a Word file that contains an Excel worksheet. You can save this document as one file and print it as one document, but you need to use both programs to edit its content. Figure 22-1 shows a couple of examples.
| || |
Figure 22-1. Top : So what do compound documents actually look like? In general, embedded and linked objects look like any other object you use in your document. For example, if you embed an Excel chart inside a Word document, the document looks just as it would if you had used Word's Insert Picture feature to place a picture of the chart in your document. The chart is stored in a floating box, and the documents text flows around it.
Bottom : If you embed a Word document inside an Excel worksheet, you get a similar but slightly less practical result. In this case, the Word document is contained inside a floating box, just like a chart or image. You can move it wherever you want.
Embedding and linking are really two different, but related , concepts.
Embedding means that a copy of one document is physically stored inside the other. For example, if you embed an Excel chart in a Word document, the Word (.doc) file contains all the Word document content and all the Excel worksheet data.
Linking means that one document contains a reference to another document. For example, if you put an Excel chart inside a Word document using linking, the Word file stores the name and file location information of the Excel workbook file. A linked document still stores some of the information from the original source, so that you have something to show even if the link gets disrupted (for example, if you delete the source file). However, the real power of a linked document is that you can refresh the link whenever you need toat which point, Excel copies the latest information from the source document.
Both embedding and linking generate the same results visually. Which one you use depends on how you plan to update the document. When you embed an object, you create a copy of the data inside the new document. You can edit that data separately, but it's no longer attached to the original source document. When you link a document, any changes you make to the source document appear in the linked document automatically. For example, if you insert a chart inside a Word document, and then modify the chart in your worksheet, the Word document also gets updated immediately.
Tip: Overall, embedding is easier to manage, but linking is the best approach if the source data changes frequently and you want to make sure the compound document always has the latest and greatest information. Linking also makes sense if you want to keep several documents synchronized with the same data (for example, you want to show an important worksheet table in four different Word reports ). Embedding usually leads to larger files because more information is placed into one file (the compound document that contains the embedded objects).
22.2.1. Exporting Charts
The best way to understand how linking and embedding work is to try it out yourself. Follow these steps to transfer an Excel chart into another Office application like Word:
Open a workbook that contains a chart.
If you don't have a chart yet, create it now.
Select the chart and choose Edit Copy.
The Windows clipboard is the key to transferring data between all Windows applications. Once you've transferred data to the clipboard, you can retrieve it in another application.
Switch to the application where you want to insert the data. Open the target document (or start a new document).
In this case, you need to switch to the Office application (like Word or PowerPoint) where you want to place the chart. If you don't have a suitable document, just select File New to create a blank document.
The Paste Special dialog box appears (see Figure 22-2).
| || |
Figure 22-2. Many Windows applications provide a Paste Special command. When you use Paste Special, you can choose to embed or link the object (depending on whether you select "Paste" or "Paste link"). You also have the option of converting the object into any of the formats listed in the "As:" list box. In this example, you can paste the Excel chart as is or convert it into an Enhanced Metafile picture.
Choose the format you want to use.
When you use the Paste Special command, the target application takes a look at the object that's on the Windows clipboard. For example, if you're pasting the chart into a Word document, Word examines the clipboard data and determines that you're copying an Excel chart. However, every chart object has the built-in smarts needed to convert itself into a picture. The Paste Special dialog box gives you the choice of pasting the actual chart object or creating a snapshot of the chart and pasting the snapshot instead.
| UP TO SPEED |
The Clipboard's One-Object Rule
Windows imposes one restriction when you copy data. You can have only one object on the clipboard at a time. That means if you copy a new object, any objects you've previously copied become unavailable. It's surprisingly easy to stumble into this problem because many different programs use the clipboard to store copied information. For example, Windows Explorer's file-copying feature or Word's text-copying tool both use the Windows clipboard and displace whatever content is currently there.
Fortunately, Excel and other Office applications don't always need to suffer from this limitation, since they have the Clipboard task, as described on Section 3.2.3 in Chapter 3. The Clipboard task shows the object that's currently on the Windows clipboard and a list of recent objects you've copied in any Office application. Of course, the Clipboard task can't help you if you're copying from information between Excel and another non-Office program because the Clipboard task is available only to Office programs.
Tip: Don't automatically decide to link or embed your charts. Pasting them as pictures sometimes offers a perfect compromise. When you paste a chart as a picture, you lose the ability to edit the chart later on. But what you gain is a much smaller overall file size (since the picture takes up much less room than an embedded object). So pasting a picture is a perfect choice if you don't want to change the chart later (or if you want to make sure that nobody messes with the chart).
Choose either "Paste" to insert an embedded object, or "Paste link" to insert a linked object.
Remember, an embedded object is a copy of the source data that's inserted into your document. A linked object is simply a reference that points to the original file.
If you choose to paste a linked object, Excel gives you one data choice onlyan Excel chart object. That's because the original data really is a chart object, not a picture. In order to convert the object into a picture, you need to create a copy of the chart, and in order to create a copy, you need to use embedding. (Word also gives you another pasting option, as explained in Figure 22-3, for those folks who simply can't wean themselves from choosing Edit Paste.)
| || |
Figure 22-3. Instead of using the Paste Special command in Word, you can simply use Edit Paste (or the shortcut Ctrl+V). In this case, Word takes its best guess about what youre trying to do and inserts an embedded picture of the chart. However, if you act fast, you can change this option by clicking the smart tag icon that appears in the bottom right corner of the picture box. When you click it, Word displays a menu with options that let you paste the chart as an embedded or linked object.
Note: When you save a document that contains embedded objects, the file itself doesn't look any different. For example, a Word document with an embedded Excel chart retains the standard .doc file extension. In fact, if you look at the file in Windows Explorer, there's no way to tell that it contains embedded Excel data in addition to its regular Word content.
Click OK to paste the object.
The object appears inside the target document in a floating box. If you pasted the chart in Word, you can right-click the chart and choose Format Object to access Word's standard layout menu, which lets you tweak whether text should flow around the edges of the object or just in the lines above and below.
Tip: You can shorten the copy-and-paste process using drag-and-drop. If you arrange your windows so that both Excel and Word are visible, you can drag the chart from the Excel window directly onto your Word document. When you release the mouse button, Word acts as though you've chosen Edit Paste and copies a picture of the chart. You can click the smart tag icon, as explained in Figure 22-3, to change the picture to a linked or embedded object.
| UP TO SPEED |
How Special Is Paste Special?
Different programs differ slightly in how they work with linking and embedding. In Office applications, the Paste Special command gives you the most flexibility, and most Windows programs provide this menu option. However, there are a few applications that don't provide a Paste Special feature, in which case you have to rely on the less nimble Paste command.
For example, consider the simple Microsoft Paint drawing program, which comes with just about every version of Windows ever created. (You can run Paint by selecting Programs Accessories Paint from the Start menu.) If you select Edit Paste from the Paint menu while an Excel chart is on the clipboard, Paint inserts a picture of your chart. Paint doesn't support object linking and embedding at all. You'll get a similar result if you try to paste your data into an HTML editing program like FrontPage.
On the other hand, if you use WordPad (select Programs Accessories WordPad from the Start menu), and you select Edit Paste, WordPad inserts an embedded Excel object. These examples just go to show that different programs make different choices when you use the Edit Paste command. To control exactly what happens, look for a Paste Special command instead.
Note: There's no reason you can't embed one object inside another, and then take that compound document and embed it as an object inside yet another application. This "Russian doll" approach probably won't accomplish anything except confusing everyone who uses the document, but it's completely possible.
22.2.2. Editing an Embedded Object
To the untrained eye, there's no way to tell if your pasted chart is a homegrown image (stored as raw picture data) or an embedded object that's owned by a specific program. Either way, it looks like a floating box that you can move around your document as you see fit. You'll only notice a difference if you want to modify your chart. If you've pasted an ordinary picture, you can't change the chart directly. Your only option is to delete the picture, edit the chart in Excel, and paste in the new one. On the other hand, if you've pasted full-fledged Excel data, you can now modify that data to alter the chart.
To confirm that your object really is an Excel chart, right-click it. In the list of options, you'll see a Chart Object submenu. If you select Chart Object, you'll see three more options: Edit, Open, and Convert. The Convert option lets you change your chart to a different supported data format, but you won't use it very often. The other two options are much more useful, since they let you edit your embedded object using all of Excel's tools.
To get a better understanding of the editing process, it helps to walk through a simple example.
Right-click a chart and choose Chart Object Edit (or just double-click the object).
Now something remarkable happensan Excel worksheet window appears inside your document. Figure 22-4 provides a closer look.
| || |
Figure 22-4. When you activate an embedded object, the object takes control of the host application like some sort of alien parasite. For example, this figure shows a Word document that contains an embedded Excel chart. Once the chart is activated, the ordinary Word menu is replaced by the Excel menu, and the Word toolbars disappear in favor of the familiar Excel versions. The end result of this strange transformation is that you get access to all of Excel's features without needing to leave the Word window.
Click the appropriate worksheet tab to change to the worksheet that has the data you want to modify.
You'll notice that the embedded Excel document has multiple worksheets. That's because when you paste an embedded chart, all the worksheet data comes along with it. Excel automatically moves the chart to a separate worksheet and displays only that worksheet in the compound document. Figure 22-5 shows another worksheet in the chart workbook.
When you're finished editing the chart's data, click the tab that contains the chart.
Make sure you move back to the chart worksheet before you deactivate the Excel object. Otherwise, the embedded object displays your worksheet data instead of your chart.
| || |
Figure 22-5. To change your data, you need to find the worksheet where the chart's data resides. This task isn't too difficult because an embedded chart object actually contains your complete workbook. You can switch from one worksheet to another using the familiar worksheet tabs. (In this picture, you can't see the Chart1 worksheet tab, but it still existsit's just to the left of the Sheet1 worksheet tab, off the display area.)
Click another part of your document to step out of Excel and back into the host program.
At this point, the program reverts to normal and all the menus and toolbars change back to their original appearance.
Sometimes, it can become awkward to edit your worksheet data inside the confines of the small window provided for an embedded object. This problem is particularly severe if you have a large amount of data. In this situation, you can choose to edit your embedded object in a standalone Excel window. Simply right-click the chart, and choose Chart Object Open. If Excel isnt already running, Windows launches it and opens a new Excel window with the chart and the related worksheet data. When you're finished making your changes, choose File Close to close the worksheet and automatically insert the new data back into your compound document.
Note: Embedded data is always stored in the document where it's embedded. In the previous example, that means there are two separate copies of the workbook. One is stored in a workbook file, and the other is embedded in the Word document. It's important to realize that these two documents are completely separate. If you modify one, it doesn't affect the other. In fact, you can even delete the original workbook file and still use the embedded one.
| FREQUENTLY ASKED QUESTION |
Super-Sized Compound Files
My compound files are giganticis there anything I can do to keep the size down?
An embedded chart object contains more than just the chartit also contains the original worksheet's data. That's because some of the data is required to build the chart. To be on the safe side, Excel embeds the entire workbook in the document. Other objects, like pictures and additional charts, also come along for the ride. These accessories are among the reasons a compound document can quickly bloat to an uncomfortably large size.
Before you embed an object, it's a good idea to create a new Excel workbook that doesn't have any unnecessary data or objects. For example, if you want to embed a chart, start by saving a new version of the workbook that contains the chart. Then, delete all the extra information in the workbook. Once you're finished paring the workbook down, you're ready to embed the chart in another application. This technique cuts down on the amount of information that the target application needs to store.
22.2.3. Editing a Linked Object
The process for editing a linked object is similar to the process for editing an embedded object. There are two key differences:
A linked object opens in a separate Excel window . You can't edit it inside the target document's window, as you can with an embedded object.
You can edit the linked object without opening the compound document . For example, if you have a Word document that contains a linked Excel chart, you can open the linked Excel file, and edit the data there. The next time you open your Word document, your changes appear automatically.
To edit a linked object in a new Excel window, right-click the object (inside the target application) and select Linked Object Edit Link. (The actual text varies slightly depending on how you inserted the object. For example, it might read Linked Chart Object or Linked Worksheet Object. Alternatively, you can bypass the menu altogether by just double-clicking the object.) What happens next depends on whether the workbook is currently open. If it is, the Excel window that contains it pops to the forefront of your screen. If not, a new Excel window opens, showing you the workbook file. You can now make any modifications you want.
When you change the linked worksheet data, the changes appear in the Word document. However, there's sometimes a delay. To trigger a refresh right away, right-click the embedded object in Word, and then choose Update Link.
In some cases, you might want to change the behavior of a linked object so that it doesn't refresh itself automatically. For example, maybe you're writing a report in Word about the trend demonstrated in a chart you've linked from Excel. Say you're worried that an automatic update might alter the chart with new results that contradict what you've written. In this case, you can instruct the host program (Word, in this case) to refrain from performing any updates until you give the go-ahead. To make this change, right-click the embedded object and choose Linked Object Links, which opens the Links dialog box. In the "Update method" section, select "Manual update." Now, the linked object gets refreshed only when you right-click it and choose Update Link. If you move the source document to a different location, you can also use the Links dialog box to fix your links. Just select the broken link (it'll say, "Source not found") and click Change Source. This opens a file browse window (like the one you need when opening a file). All you need to do is browse to the new location of the source file, select it, and click Open.
Note: Linking works particularly well if you want to insert only a small part of a much larger workbook. Linking doesn't increase the size of the target document because it only stores a link to the worksheet containing the data you're using.
22.2.4. Importing Objects
You can use the same process described in the previous section to copy objects out of other programs and place them inside Excel. In Excel, embedded objects appear as floating boxes (like pictures and charts). You can position these floating boxes wherever you want on your worksheet.
Embedding doesn't make sense for all types of objects. As Figure 22-1 showed, a Word document object doesn't integrate all that naturally into an Excel worksheet. However, other type of objects might make more sense. One example is an image format that Excel doesn't support. You could paste this image as an embedded object by copying it from the appropriate drawing program. The trick is Excel's Edit Paste Special command, which works in the same way as all the other Office applications, including Word.
Figure 22-6 shows an example of an object that's been transferred from Visio, a program that helps create diagrams.