Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

OLE2 Excel File Save as password protected

Former Member
0 Kudos
423

Hi All,

I would like to save an Excel File as Password protected.

This File is created by OLE2.

How can I do this?

This is the Coding, how I save the File-->

CALL METHOD OF ls_wbook 'SaveAs' EXPORTING #1 = p_file.

Thanks for the Answers...

Bye

Besi

3 REPLIES 3

juan_suros
Contributor
0 Kudos
91

This will work:

REPORT  YZZZZZ.


INCLUDE OLE2INCL.


DATA: oExcel        TYPE OLE2_OBJECT,
      oWBs          TYPE OLE2_OBJECT,
      oWB           TYPE OLE2_OBJECT,
      P_file(50)    TYPE C VALUE 'C:test.xls',
      P_pwd(10)     TYPE C VALUE 'HELLO'.


* Start a new copy of Excel
  CREATE OBJECT oExcel 'EXCEL.APPLICATION'.


* Get list of workbooks, initially empty
  CALL METHOD OF oExcel 'Workbooks' = oWBs.


* Add a new workbook, keep a reference to it
  CALL METHOD OF oWBs 'Add' = oWB.


* Set password for Excel file
  SET PROPERTY OF oWB 'Password' = P_pwd.


* Save file
  CALL METHOD OF oWB 'SaveAs' EXPORTING #1 = P_file

0 Kudos
91

Hi Juan,

It did not work. If I set this Coding-->

SET PROPERTY OF oWB 'Password' = P_pwd.

,the Excel File will not be saved.

Bye

Besi

0 Kudos
91

Hello Besi,

The following code should work. Try it out.

CALL METHOD OF document 'Protect' EXPORTING

#1 = 2

#2 = -1

#3 = 'password'.

CALL METHOD OF documents 'Save'.

Here 'document' is the 'ActiveDocument' object.

How to get the 'document' object:

CREATE OBJECT worddoc 'Word.Document'.

GET PROPERTY OF worddoc 'Application' = wordapp.

GET PROPERTY OF wordapp 'ActiveDocument' = document.

Regards,

Jitendar