Skip to Content
avatar image
Former Member

MailMerge in Word using SAP - Problem with locking variable fields in document header - OLE

I'm developing a custom tool to use SAP to perform MailMerge on office Word. From a table in SAP I let the system populate the variables contained in the header of a Word template in order to print it. To do this we are using some standard OLE instructions, marking the document as final before to preview it, in order to make it not changeable and to keep variables' values.

But we noticed that this "trick" works only on Word versions until 2007. After this version is no longer possible to keep variables' values in header if the document is just "marked as final" (this is a problem due to the Word versions very common on the internet). So I tried to use the lock functionality (CTRL+F11) that should work always (and it works if I try on a Word document with variables in header). But someway instructions don't do their job through SAP! I paste here the whole instructions, I'm not an abaper but I hope you experts have any idea to overcome this issue.

Thank you in advance!

PS. I'm using SAP GUI 740 last patched and I already referred to several SAP notes (mainly 1645315 and 2100448)

-----------------------------------------------------------------------------------------------------------------------

CALL METHOD OF w_word 'ActiveWindow' = w_activewindow.
IF sy-subrc NE 0 .
MESSAGE i398(00) WITH 'Error ActiveWindow'.
LEAVE PROGRAM .
ENDIF .

CALL METHOD OF w_activewindow 'ActivePane' = w_activepane.
IF sy-subrc NE 0 .
MESSAGE i398(00) WITH 'Error ActivePane'.
LEAVE PROGRAM .
ENDIF .

CALL METHOD OF w_activepane 'View' = w_activeview.
IF sy-subrc NE 0 .
MESSAGE i398(00) WITH 'Error View'.
LEAVE PROGRAM .
ENDIF .

SET PROPERTY OF w_activeview 'SeekView' = '9'. " header view.
IF sy-subrc NE 0 .
MESSAGE i398(00) WITH 'Error SeekView = 9'.
LEAVE PROGRAM .
ENDIF .
*
* Selection.WholeStory
* Selection.Fields.Locked = True
CALL METHOD OF w_activepane 'Selection' = w_selection.
IF sy-subrc NE 0 .
MESSAGE i398(00) WITH 'Error Selection'.
LEAVE PROGRAM .
ENDIF .

* Selection.WholeStory
CALL METHOD OF w_selection 'WholeStory' = w_wholestory.
IF sy-subrc NE 0 .
MESSAGE i398(00) WITH 'Error WholeStory'.
LEAVE PROGRAM .
ENDIF .

CALL METHOD OF w_selection 'Fields' = w_fields.
IF sy-subrc NE 0.
ENDIF.

move 1 to ld_locked.
CALL METHOD OF w_fields 'Locked' = ld_locked.
IF sy-subrc NE 0.

ENDIF.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Jul 03, 2017 at 06:18 AM

    I did an ABAP controlled Word mail merge back in 2003. We used simple text replace, replacing tags like <<docno>> with the document number, for example, rather than variables.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank you for sharing, I will consider this as a last chance maybe.
      I've the feeling we are near to the solution, but something is still missing.

      Any other idea regarding this issue?

  • Jul 03, 2017 at 06:26 PM

    You should better ask the question in a non-ABAP forum, especially stackoverflow.

    Add comment
    10|10000 characters needed characters exceeded