Code: Alles auswählen.
call method of word 'APPCLOSE'
exporting #1 = 'X'.
free object: word.
word-handle = -1.
Danke im VorausSoll das Dokument schreibgeschützt geöffnet werden ?
Code: Alles auswählen.
FUNCTION ZZ_FILL_WORD_OLE.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(FILE) TYPE LOCALFILE
*" REFERENCE(DISPLAY) TYPE CHAR1 OPTIONAL
*" REFERENCE(PRINT) TYPE CHAR1 OPTIONAL
*" REFERENCE(SAVE) TYPE CHAR1 OPTIONAL
*" REFERENCE(SAVE_AS) TYPE LOCALFILE OPTIONAL
*" TABLES
*" BOOKMARKS TYPE ZTWORD_BOOKMARK
*" EXCEPTIONS
*" FILE_NOT_FOUND
*" MSWORD_NOT_FOUND
*" SAVE_ERROR
*"----------------------------------------------------------------------
include ole2incl.
data: word type ole2_object.
* Word öffnen
create object word 'WORD.BASIC'.
if sy-subrc ne 0.
raise msword_not_found.
exit.
endif.
* Datei öffnen
call method of word 'FILEOPEN'
exporting #1 = file.
if sy-subrc ne 0.
call method of word 'APPCLOSE'.
free object word.
raise file_not_found.
exit.
endif.
* Über die Bookmark-Tabelle loopen und Text in Datei schreiben
loop at bookmarks.
call method of word 'EDITBOOKMARK'
exporting #1 = bookmarks-bookmark
#2 = 0
#3 = 0
#4 = 0
#5 = 1.
call method of word 'INSERT'
exporting #1 = bookmarks-text.
endloop.
* Speichern ?
if save = 'X'.
if save_as is initial.
call method of word 'FileSave'.
else.
call method of word 'FileSaveAs'
exporting #1 = SAVE_AS.
if sy-subrc ne 0.
raise save_error.
endif.
endif.
endif.
* Drucken ?
if print = 'X'.
call method of word 'FILEPRINT'.
endif.
* Word anzeigen ?
if display = 'X'.
call method of word 'APPSHOW'.
else.
call method of word 'APPCLOSE'
exporting #1 = 'X'.
endif.
free object: word.
word-handle = -1.
free word.
ENDFUNCTION.