01-10-2005 2:18 PM
Does anyone know a method to protect an Excel workbook from Abap (the equivalent of 'Tools->Protection->Protect Workbook in Excel)?
Regards,
John.
01-10-2005 2:27 PM
Hi Fuat,
Thanks for the quick reaction, but that is not the solution. The 'Protect' method of the spreadsheet interface just protects cells from being overwritten. I want to protect the workbook from all kinds of editing to the structure (e.g. renaming sheets) as the 'Tools->Protection->Protect Workbook' does.
Regards,
John.
01-10-2005 2:21 PM
SAP Help
Here you can find detailed information about excel integration.
http://help.sap.com/saphelp_47x200/helpdata/en/21/b53138e1ba11d2bdbe080009b4534c/frameset.htm
Message was edited by: Fuat Ulugay
01-10-2005 2:27 PM
Hi Fuat,
Thanks for the quick reaction, but that is not the solution. The 'Protect' method of the spreadsheet interface just protects cells from being overwritten. I want to protect the workbook from all kinds of editing to the structure (e.g. renaming sheets) as the 'Tools->Protection->Protect Workbook' does.
Regards,
John.
01-10-2005 2:54 PM
Hi John,
I just did a quick test in Excel and found the following VBA code protected the workbook:
ActiveWorkbook.Protect "mypass", True, False
Cheers,
Scott
01-10-2005 3:10 PM
Hi Scott,
We're getting there, but now the equivalent to be used in Abap. I tried already "CALL METHOD OF workbook 'PROTECT' " after opening the Excel workbook, but the returncode is set to '02'.
Regards,
John.
01-10-2005 3:28 PM
Hi John
Did you try passing the password parameter? And are you sure 'workbook' is the active workbook object?
<u><b>e.g.</b></u>
CALL METHOD OF workbook 'Protect'
EXPORTING #1 = <pass> .
*--Serdar
01-10-2005 3:39 PM
Hi Serdar,
I (think I) am sure. But for the record the piece of coding:
PROGRAM zjh.
TYPE-POOLS ole2.
DATA excel TYPE ole2_object.
DATA workbook TYPE ole2_object.
CREATE OBJECT excel 'Excel.Application'.
SET PROPERTY OF excel 'Visible' = 1.
CALL METHOD OF excel 'Workbooks' = workbook.
CALL METHOD OF workbook 'Open'
EXPORTING #1 = 'C:\TESTJOHN.XLS'.
CALL FUNCTION 'FLUSH'.
CALL METHOD OF workbook 'PROTECT'
EXPORTING #1 = 'password'.
With a break-point on the last statement the excel workbook is opened correctly; however executing the last statement will give returncode '02'.
Any suggestions?
John.
01-10-2005 3:58 PM
I haven't tested the logic properly, but from the code shown, it looks like variable "workbook" contains a reference to a Workbooks object rather than an instance of a Workbook object. I suspect return code 02 is returned because there is no Protect method for the Workbooks object???
Cheers,
Scott
01-10-2005 4:07 PM
Have done a test now, found the following variation of your code to work...
REPORT zz_bardens_excel .
TYPE-POOLS:
ole2.
DATA:
excel TYPE ole2_object,
workbooks TYPE ole2_object,
workbook TYPE ole2_object.
START-OF-SELECTION.
CREATE OBJECT excel 'Excel.Application'.
SET PROPERTY OF excel 'Visible' = 1.
GET PROPERTY OF excel 'Workbooks' = workbooks.
CALL METHOD OF workbooks 'Add'.
GET PROPERTY OF excel 'ActiveWorkbook' = workbook.
CALL METHOD OF workbook 'PROTECT'
EXPORTING #1 = 'password'.
WRITE sy-subrc.
Scott
01-10-2005 4:16 PM
Thanks Scott!
This works fine, 10 points for you! However, I'm still wondering if there is any decent documentation for all the methods you can call?
Regards,
John
01-10-2005 4:44 PM
Wow, that's my second lot of points today. I think I need a nap.
I just use the VBA Help file that comes with Microsoft Excel (if you chose the option to install it). Open up the VBA editor from the Macros menu in Excel and then go to its help menu.
Cheers,
Scott