Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. AddOLEObject with LinkToFile on Word 2007 (MFC)

AddOLEObject with LinkToFile on Word 2007 (MFC)

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++comquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dy
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups