CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: InvokeHelper

  1. #1
    Guest

    InvokeHelper

    I am trying to insert a file into an existing word document (the file to be inserted is a word document as well). I created a Range object (used msword8.olb) and after strugging with the param conversion I came up with the following:

    //dispatch interface
    LPDISPATCH wordDisp=pActiveItem->GetIdispatch();

    _Document wordDoc(wordDisp); //valid
    Range rangeDoc(wordDisp); //valid??

    if (wordDisp!=NULL)
    {
    COleVariant covOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
    COleVariant covFalse((short)FALSE);

    CString csFile="docinsert.doc";

    rangeDoc.InsertFile(csFile,&covOptional,&covOptional,&covOptional,&covOptional);
    }

    the InsertFile fails with invalid number of parameters. The dispatch interface is valid as I am able to use the wordDoc object to save the file being edited in my application. Any help would be appreciated.



  2. #2
    Join Date
    Apr 2003
    Location
    Cologne
    Posts
    7
    Hi!!!

    I just had the same problem and searched quite a time to solve it.
    The trick is, as always, pretty simple as long as you know it:

    The RANGE param isnt a real Range Object. Just try this:

    //Prepare an "empty" range (where range at this time is meant as "string"

    VARIANT var;
    VariantInit(&var);
    var.vt = VT_BSTR;
    var.bstrVal = BSTR("");

    //the call:
    Selection.InsertFile("FILE.doc", &var,
    COleVariant((long) 0, VT_BOOL),
    COleVariant((long) 0, VT_BOOL),
    COleVariant((long) 0, VT_BOOL)
    );

    This works just fine.

    Greetz
    Chameleon
    Last edited by Chameleon; April 14th, 2003 at 09:45 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured