<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Write Code in Excel thru SAP in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/write-code-in-excel-thru-sap/m-p/2554178#M581958</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;???&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Jul 2007 12:38:47 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-07-18T12:38:47Z</dc:date>
    <item>
      <title>Write Code in Excel thru SAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/write-code-in-excel-thru-sap/m-p/2554176#M581956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i have made report in SAP which directly opens in Excel,&lt;/P&gt;&lt;P&gt;i have protected the sheet but my requirement is that user shud not be able to cut Copy and paste the data from that sheet while protecting he is unable to do any modification my reqt is that he shud not be allowed to cut and copy the data also.&lt;/P&gt;&lt;P&gt;i have written the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

REPORT  z_test.



INCLUDE ole2incl.

* handles for OLE objects
DATA: h_excel   TYPE ole2_object,        " Excel object
      h_mapl    TYPE ole2_object,        " list of workbooks
      h_map     TYPE ole2_object,        " workbook
      h_cell    TYPE ole2_object,        " cell
      h_f       TYPE ole2_object,        " font
      h_col     TYPE ole2_object,
      h_row     TYPE ole2_object,
      h_int     TYPE ole2_object,
      h_auto    TYPE ole2_object,
      h_select  TYPE ole2_object,
      h_range   TYPE ole2_object,
      h_merge   TYPE ole2_object,
      h_columns TYPE ole2_object,
      h_rows    TYPE ole2_object,
      h_borders TYPE ole2_object,
      h_active  TYPE ole2_object,
      row       TYPE i,
      col       TYPE i,
      v_prog(70),
      v_range1(10),
      v_range2(10),
      v_r1(10),
      v_r2(10).

*----------------------------------------------------------------------
*


START-OF-SELECTION .

END-OF-SELECTION .
  PERFORM f_start_excel .
  PERFORM f_display_hdr .
  PERFORM f_stop_excel .
*


*&amp;amp;---------------------------------------------------------------------
*
*&amp;amp;      Form  f_start_excel
*&amp;amp;---------------------------------------------------------------------
*
FORM f_start_excel .
* start Excel
  CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
  SET PROPERTY OF h_excel  'Visible' = 1.

* get list of workbooks, initially empty
  CALL METHOD OF h_excel 'Workbooks' = h_mapl.
  PERFORM err_hdl.
* add a new workbook
  CALL METHOD OF h_mapl 'Add' = h_map.
  PERFORM err_hdl.
ENDFORM.                    " f_start_excel
*&amp;amp;---------------------------------------------------------------------
*&amp;amp;      Form  f_stop_excel
*&amp;amp;---------------------------------------------------------------------
*
FORM f_stop_excel .
  FREE OBJECT h_cell.

  CALL METHOD OF h_excel 'Cells' = h_cell .
  GET PROPERTY OF h_cell  'Select' = h_select.

  CALL METHOD OF h_cell 'Columns' = h_columns .
  CALL METHOD OF h_columns 'AutoFit' = h_auto .

  CALL METHOD OF h_cell 'Rows' = h_rows .
  CALL METHOD OF h_rows 'AutoFit' = h_auto .

  FREE OBJECT h_cell.

  CALL METHOD OF h_excel 'Cells' = h_cell
    EXPORTING
    #1 = 1
    #2 = 1.
  GET PROPERTY OF h_cell  'Select' = h_select.


  GET PROPERTY OF h_excel 'ActiveSheet' = h_active.

  CALL METHOD  OF h_active 'PROTECT'
    EXPORTING #1 = 'password'.


*
  SET PROPERTY OF h_excel  'Visible' = 1.

  FREE OBJECT h_excel.
  PERFORM err_hdl.
ENDFORM.                    " f_stop_excel
*&amp;amp;---------------------------------------------------------------------
*
*&amp;amp;      Form  ERR_HDL
*&amp;amp;---------------------------------------------------------------------
*
FORM err_hdl.
  IF sy-subrc &amp;lt;&amp;gt; 0.
    WRITE: / 'OLE Error :'(010), sy-subrc.
    STOP.
  ENDIF.
ENDFORM.                    " ERR_HDL


*&amp;amp;---------------------------------------------------------------------
*
*&amp;amp;      Form  f_display_hdr
*&amp;amp;---------------------------------------------------------------------
*
FORM f_display_hdr .
  row = 2 .
  PERFORM fill_cell USING row 3 'OHO SHEET'  1 35 1 1 0 16 0 1.
  PERFORM f_merge_cells USING 'A' 'E' -4108 .

  row = row + 2  .
  PERFORM fill_cell USING row 3 'Program Details'  1 43 1 1 0 12 0 1.
  PERFORM f_merge_cells USING 'A' 'E' -4108 .

ENDFORM.                    " f_display_hdr
*---------------------------------------------------------------------*
*       FORM FILL_CELL                                                *
*---------------------------------------------------------------------*
FORM fill_cell USING p_row    p_col    p_val  p_shrink p_bkclr p_pat
                     p_bold   p_italic p_size p_fclr   p_uline .

  CALL METHOD OF h_excel 'Cells' = h_cell
    EXPORTING
    #1 = p_row
    #2 = p_col.

  SET PROPERTY OF h_cell 'Value'       = p_val .
  SET PROPERTY OF h_cell 'ShrinkToFit' = p_shrink .

  GET PROPERTY OF h_cell 'Interior'   = h_int.
  SET PROPERTY OF h_int  'ColorIndex' = p_bkclr .
  SET PROPERTY OF h_int  'Pattern'    = p_pat.

  GET PROPERTY OF h_cell 'Font'    = h_f.
  SET PROPERTY OF h_f 'Bold'       = p_bold .
  SET PROPERTY OF h_f 'Italic'     = p_italic .
  SET PROPERTY OF h_f 'Size'       = p_size .
  SET PROPERTY OF h_f 'ColorIndex' = p_fclr .
  SET PROPERTY OF h_f 'Name'       = 'Arial' .
  SET PROPERTY OF h_f 'Underline'  = p_uline .
ENDFORM.                    "FILL_CELL
*&amp;amp;---------------------------------------------------------------------
*
*&amp;amp;      Form  f_merge_cells
*&amp;amp;---------------------------------------------------------------------
*
FORM f_merge_cells USING p_r1 p_r2 p_val.
  CLEAR : v_r1, v_r2, v_range1, v_range2 .

  v_range1 = row .
  v_range2 = row .
  SHIFT v_range1 LEFT DELETING LEADING ' ' .
  SHIFT v_range2 LEFT DELETING LEADING ' ' .

  CONCATENATE p_r1 v_range1 INTO v_r1 .
  CONCATENATE p_r2 v_range2 INTO v_r2 .

  CALL METHOD OF h_excel 'Range' = h_range
    EXPORTING
    #1 = v_r1
    #2 = v_r2.
  CALL METHOD OF h_range 'Select' = h_select .
  CALL METHOD OF h_range 'Merge' = h_merge .
  SET PROPERTY OF h_range 'HorizontalAlignment' = p_val.
ENDFORM.                    " f_merge_cells



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i ave found the code for visual basi editor&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Option Explicit &lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;Sub ToggleCutCopyAndPaste(Allow As Boolean) &lt;/P&gt;&lt;P&gt;     'Activate/deactivate cut, copy, paste and pastespecial menu items &lt;/P&gt;&lt;P&gt;    Call EnableMenuItem(21, Allow) ' cut &lt;/P&gt;&lt;P&gt;    Call EnableMenuItem(19, Allow) ' copy &lt;/P&gt;&lt;P&gt;    Call EnableMenuItem(22, Allow) ' paste &lt;/P&gt;&lt;P&gt;    Call EnableMenuItem(755, Allow) ' pastespecial &lt;/P&gt;&lt;P&gt;      &lt;/P&gt;&lt;P&gt;     'Activate/deactivate drag and drop ability &lt;/P&gt;&lt;P&gt;    Application.CellDragAndDrop = Allow &lt;/P&gt;&lt;P&gt;      &lt;/P&gt;&lt;P&gt;     'Activate/deactivate cut, copy, paste and pastespecial shortcut keys &lt;/P&gt;&lt;P&gt;    With Application &lt;/P&gt;&lt;P&gt;        Select Case Allow &lt;/P&gt;&lt;P&gt;        Case Is = False &lt;/P&gt;&lt;P&gt;            .OnKey "^c", "CutCopyPasteDisabled" &lt;/P&gt;&lt;P&gt;            .OnKey "^v", "CutCopyPasteDisabled" &lt;/P&gt;&lt;P&gt;            .OnKey "^x", "CutCopyPasteDisabled" &lt;/P&gt;&lt;P&gt;            .OnKey "+&lt;SPAN __jive_macro_name="DEL"&gt;", "CutCopyPasteDisabled" 
            .OnKey "^&lt;SPAN __jive_macro_name="INSERT"&gt;&lt;/SPAN&gt;", "CutCopyPasteDisabled" 
        Case Is = True 
            .OnKey "^c" 
            .OnKey "^v" 
            .OnKey "^x" 
            .OnKey "+&lt;/SPAN&gt;" &lt;/P&gt;&lt;P&gt;            .OnKey "^&lt;SPAN __jive_macro_name="INSERT"&gt;&lt;/SPAN&gt;" &lt;/P&gt;&lt;P&gt;        End Select &lt;/P&gt;&lt;P&gt;    End With &lt;/P&gt;&lt;P&gt;End Sub &lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;Sub EnableMenuItem(ctlId As Integer, Enabled As Boolean) &lt;/P&gt;&lt;P&gt;     'Activate/Deactivate specific menu item &lt;/P&gt;&lt;P&gt;    Dim cBar As CommandBar &lt;/P&gt;&lt;P&gt;    Dim cBarCtrl As CommandBarControl &lt;/P&gt;&lt;P&gt;    For Each cBar In Application.CommandBars &lt;/P&gt;&lt;P&gt;        If cBar.Name &amp;lt;&amp;gt; "Clipboard" Then &lt;/P&gt;&lt;P&gt;            Set cBarCtrl = cBar.FindControl(ID:=ctlId, recursive:=True) &lt;/P&gt;&lt;P&gt;            If Not cBarCtrl Is Nothing Then cBarCtrl.Enabled = Enabled &lt;/P&gt;&lt;P&gt;        End If &lt;/P&gt;&lt;P&gt;    Next &lt;/P&gt;&lt;P&gt;End Sub &lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;Sub CutCopyPasteDisabled() &lt;/P&gt;&lt;P&gt;     'Inform user that the functions have been disabled &lt;/P&gt;&lt;P&gt;    MsgBox "Sorry!  Cutting, copying and pasting have been disabled in this workbook!" &lt;/P&gt;&lt;P&gt;End Sub &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="---------------------------------------" /&gt;&lt;P&gt;WORKBOOK EVENTS IN the this workbook -&lt;/P&gt;&lt;HR originaltext="-----------------------------------" /&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Private Sub Workbook_Activate() &lt;/P&gt;&lt;P&gt;    Call ToggleCutCopyAndPaste(False) &lt;/P&gt;&lt;P&gt;End Sub &lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;Private Sub Workbook_BeforeClose(Cancel As Boolean) &lt;/P&gt;&lt;P&gt;    Call ToggleCutCopyAndPaste(True) &lt;/P&gt;&lt;P&gt;End Sub &lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;Private Sub Workbook_Deactivate() &lt;/P&gt;&lt;P&gt;    Call ToggleCutCopyAndPaste(True) &lt;/P&gt;&lt;P&gt;End Sub &lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;Private Sub Workbook_Open() &lt;/P&gt;&lt;P&gt;    Call ToggleCutCopyAndPaste(False) &lt;/P&gt;&lt;P&gt;End Sub &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but how to use this code in SAP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jul 2007 11:12:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/write-code-in-excel-thru-sap/m-p/2554176#M581956</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-18T11:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Write Code in Excel thru SAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/write-code-in-excel-thru-sap/m-p/2554177#M581957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't think it can be done, because drag&amp;amp;drop, copy&amp;amp;paste is handled not by the excel, but the windows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might try out to set the cells property to read-only (this prevents their overwriting).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Tamá&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jul 2007 11:17:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/write-code-in-excel-thru-sap/m-p/2554177#M581957</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-18T11:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: Write Code in Excel thru SAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/write-code-in-excel-thru-sap/m-p/2554178#M581958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;???&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jul 2007 12:38:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/write-code-in-excel-thru-sap/m-p/2554178#M581958</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-18T12:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Write Code in Excel thru SAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/write-code-in-excel-thru-sap/m-p/2554179#M581959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;?? any clues&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2007 11:20:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/write-code-in-excel-thru-sap/m-p/2554179#M581959</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-19T11:20:30Z</dc:date>
    </item>
  </channel>
</rss>

