Skip to Content
author's profile photo Former Member
Former Member

Need help with OLE2

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 02, 2014 at 07:49 PM

    Solved this by myself.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.