Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Set Password to a MS Word File that is in PC, Then Save File with OLE

Hi,

there is a ms word file in local computer, i want to set password to that file and save again.

we are creating ms word file with ole with following codes;

*-- create word file
DATA: gs_word         TYPE ole2_object ,
      gs_documents    TYPE ole2_object ,
      gs_newdoc       TYPE ole2_object ,
      gs_selection    TYPE ole2_object ,
      gs_application  TYPE ole2_object ,
      gs_actdoc       TYPE ole2_object .

  CREATE OBJECT gs_word 'WORD.APPLICATION' .
  IF sy-subrc NE 0 .
    MESSAGE s000(su) WITH 'Error while creating OLE object!'.
    LEAVE PROGRAM .
  ENDIF .

  SET PROPERTY OF gs_word 'Visible' = '0' .
  CALL METHOD OF gs_word 'Documents' = gs_documents.
  CALL METHOD OF gs_documents 'Add' = gs_newdoc.
  call method of gs_newdoc 'Activate' = gs_actdoc.

CALL METHOD OF gs_word 'ActiveDocument' = gs_actdoc .

GET PROPERTY OF gs_actdoc 'Application' = gs_application .


  GET PROPERTY OF gs_word 'Selection' = gs_selection.

   CALL METHOD OF gs_actdoc 'SaveAs'
    EXPORTING
      #1 = p_file "'C:\file.doc'          "filename
      #2 = 1                      "fileFormat
      #3 = 0                      "LockComments
      #4 = sy-uname             "password to open a workbook
      #5 = 0                      "AddToRecentFiles
      #6 = sy-uname.             "password for write access

*CALL METHOD OF gs_actdoc 'PrintOut' .

    CALL METHOD OF gs_word 'Quit' .

    FREE: gs_word, gs_actdoc, gs_documents , gs_newdoc .
*--

this code is creating a blank file that has been in pc and hadn't been a blank file but has a password.

i think it happens with this code ;

CALL METHOD OF gs_documents 'Add' = gs_newdoc.

is there another method instead of 'Add'? or how can i set password to ms word file that has been in pc?

Thanks.

Former Member
Not what you were looking for? View more on this topic or Ask a question