Board index » delphi » OLE 2 with MS Word (setting field values in documents)

OLE 2 with MS Word (setting field values in documents)

Has someone ever taken control of a MS Word 7 document with OLE and D2??  My prblm is setting
field values within the document.  I proceed as follows:

Var ole:  variant;
begin
 ole.fileopen('e:\my documents\test');
 ole.editgoto('FieldName');     // this works fine:  the Word cursor
                                //goes to the field

  // I THEN ATTEMPT WRITING TEXT IN THE FIELD
 ole.insert('My name');  // this does not work

 ole.putfielddata('My name again');  // does not work either
 end;

I tried this with Form fields.  The cursor could move to the field, but the error msg "Field is
not an ADDIN field" or "Field cannot accept data" is displayed.

With mail-merge fields, nothing works.

If I run a WordBasic macro directly from Word, with a form field and the command "insert" as
shown above, everything works fine.

What am I doing wrong?????????????

One final note:  If I protect the document as a form, the pgm behaves as described above.  If
the document is left unprotected, the cursor is moved to the field, and the INSERT command
_overwrites_ it:  there no longer is a field there after that.

Anyone has a clue??

Thanks in advance.

Pls do not hesitate to e-mail...

Michel Ranger
micr...@cam.org

 

Re:OLE 2 with MS Word (setting field values in documents)


Quote
Michel Ranger wrote:

> Has someone ever taken control of a MS Word 7 document with OLE and D2??  My prblm is setting
> field values within the document.  I proceed as follows:

> Var ole:  variant;
> begin
>  ole.fileopen('e:\my documents\test');
>  ole.editgoto('FieldName');     // this works fine:  the Word cursor
>                                 //goes to the field

>   // I THEN ATTEMPT WRITING TEXT IN THE FIELD
>  ole.insert('My name');  // this does not work

>  ole.putfielddata('My name again');  // does not work either
>  end;

> I tried this with Form fields.  The cursor could move to the field, but the error msg "Field is
> not an ADDIN field" or "Field cannot accept data" is displayed.

> With mail-merge fields, nothing works.

> If I run a WordBasic macro directly from Word, with a form field and the command "insert" as
> shown above, everything works fine.

> What am I doing wrong?????????????

> One final note:  If I protect the document as a form, the pgm behaves as described above.  If
> the document is left unprotected, the cursor is moved to the field, and the INSERT command
> _overwrites_ it:  there no longer is a field there after that.

> Anyone has a clue??

> Thanks in advance.

> Pls do not hesitate to e-mail...

> Michel Ranger
> micr...@cam.org

I answer my own question.  The solution is to use the word basic procedure SETFORMRESULT(<field
bookmark>, <string>).

I still don't know why the ole.insert command does not work when entering data in fields, but I
don't really care anymore.

I hope this will have saved someone a few hours of frustration.

Michel Ranger
micr...@cam.org

Other Threads