05-29-2014 12:05 AM
Hi,
I'm trying to learn OLE2 in ABAP, in particular getting processing in ABAP and create a Word document with the result. I've written a small program and all I want to do, is for a Word document to be created with the header, body and footer fill in with some simple text. Of course, this doesn't work. The ABAP is a mix and match from sample codes I found here and also some guess work based on VBA. I don't know VBA, to be honest so I'm sure I got lots of stuff wrong.
Can anyone help?
REPORT ZTEST.
INCLUDE ole2incl.
TYPE-POOLS: ole2.
DATA: obj_ms_word TYPE ole2_object,
obj_activewindow TYPE ole2_object,
obj_activepane TYPE ole2_object,
lv_documents TYPE ole2_object,
lv_thisdoc TYPE ole2_object,
lv_activeview TYPE ole2_object,
w_activewindow TYPE ole2_object,
w_activepane TYPE ole2_object,
w_activeview TYPE ole2_object,
w_selection TYPE ole2_object.
CREATE OBJECT obj_ms_word 'Word.Application'.
CALL METHOD of obj_ms_word 'ActiveWindow' = w_activewindow.
CALL METHOD of obj_activewindow 'ActivePane' = w_activepane.
CALL METHOD of obj_activepane 'View' = w_activeview.
CALL METHOD OF obj_ms_word 'Documents' = lv_documents.
CALL METHOD OF lv_documents 'Add' = lv_thisdoc.
CALL METHOD OF lv_thisdoc 'Activate'.
GET PROPERTY OF obj_ms_word 'Selection' = w_selection.
*For the header
SET PROPERTY OF w_activeview 'SeekView' = '9'.
CALL METHOD OF w_selection 'TypeText'
EXPORTING
#1 = 'This is the header'.
*For the body
SET PROPERTY OF w_activeview 'SeekView' = '0'.
CALL METHOD OF w_selection 'TypeText'
EXPORTING
#1 = 'This is the body'.
*For the footer
SET PROPERTY OF w_activeview 'SeekView' = '10'.
CALL METHOD OF w_selection 'TypeText'
EXPORTING
#1 = 'This is the footer'.
SET PROPERTY OF obj_ms_word 'Visible' = 1.
FREE OBJECT obj_ms_word.
TIA.
06-02-2014 8:49 PM
06-02-2014 8:49 PM