AddOLEObject with LinkToFile on Word 2007 (MFC)
-
Hi, I have the following code, which is adding an OLE object to a word document, linking the OLE file to the document so that the document can be moved to another machine without the linked file, and the linked file can still be seen/activated. When the code executes on a machine with Office XP, the code functions as desired and the resulting .doc file is ~1.5mb (expected). However, when the code is executed on a machine with Office 2007, the code returns no error, but the resulting file is much smaller (~20kb), and when I double click the OLE object to activate it (having removed the linked object to test it's linked correctly), nothing happens. When I right click on the OLE object and select 'Object', I get a message saying "The object is corrupt or is no longer available". It's as though the LinkToFile = true has been ignored by Word 2007 - is that the case? Or is there a problem with my code?
// Start winword MicrosoftWord :: \_Application lApp; if (!lApp.CreateDispatch(\_T("Word.Application"))) { AfxMessageBox(\_T("sorry old chap, winword's not playing ball")); return; } // Handy variants COleVariant lTrue((short) TRUE); COleVariant lFalse((short) FALSE); COleVariant lMissing((long) DISP\_E\_PARAMNOTFOUND, VT\_ERROR); // Documents collection / manager MicrosoftWord :: Documents lDocsMgr(lApp.GetDocuments()); // Create a new document MicrosoftWord :: \_Document lDoc; lDoc.AttachDispatch(lDocsMgr.Add(lMissing, lFalse)); // Add an OLE AVI file MicrosoftWord :: Selection lContent(lApp.GetSelection()); CString aFileName = \_T("c:\\\\temp\\\\my.avi"); MicrosoftWord :: InlineShapes lShapeCollection(lContent.GetInlineShapes()); lShapeCollection.AddOLEObject(lMissing, COleVariant(aFileName), lTrue, lFalse, lMissing, lMissing, lMissing, lMissing); // Save the document (c:\\temp\\abc.doc) & quit lDoc.SaveAs(COleVariant(\_T("c:\\\\temp\\\\abc.doc")), lMissing, lMissing, lMissing, lMissing, lMissing, lMissing, lMissing, lMissing, lMissing, lMissing); lDoc.Close(lMissing, lMissing, lMissing); lApp.Quit(lMissing, lMissing, lMissing);
Many thanks, - Dylan
- Dy