Skip to Content
0
Former Member
May 25, 2005 at 04:17 PM

OLE / ms WORD / Create new document, insert image and print

472 Views

Hello gurus,

I need to create a new ms word document, write a variable text, insert an image, print the document and close it.

I am new at OLE programming. I have been checking the weblog of Sedar and the examples of SAP and have as a result the following code:

include ole2incl .

parameters: p_id type crmt_object_id.

data: gs_word type ole2_object,

gs_documents type ole2_object,

gs_newdoc type ole2_object,

gs_actdoc type ole2_object,

gs_picture(128).

start-of-selection .

gs_picture = 'c:\0000002257_01.TIF'.

create object gs_word 'WORD.APPLICATION'.

set property of gs_word 'Visible' = '1' .

call method of gs_word 'Documents' = gs_documents.

call method of gs_documents 'FileNew' = gs_newdoc

exporting

#1 = 'c:\my_doc.doc'.

call method of gs_word 'ActiveDocument' = gs_actdoc.

call method of gs_word 'TypeText'

exporting

#1 = p_id.

call method of gs_word 'InsertPicture'

exporting

#1 = gs_picture

#2 = '2'.

call method of gs_actdoc 'PrintOut' .

call method of gs_actdoc 'SaveAs'

exporting

#1 = 'c:\my_doc.doc'

#2 = 'wdFormatDocument'.

call method of gs_word 'Quit' .

end-of-selection.

free: gs_word, gs_actdoc, gs_documents, gs_newdoc.

Could anybody tell me why it is not working? I am using the SaveAs because the Quit returns sy-subrc = 2, and thougth it was possible that since I had modified the document, it was necesary to save it.

Thank you!

Paola