How to translate an excel macro to ABAP code

Hi Guys,
My requirement is need to put the subtotaling option w.r.t divison when i download the file to an excel sheet via OLE.
Iam able to get the records in the excel sheet but unable to write the macro in ABAP code.
the macro which i recorded in Excel is
Range("A1:C3").Select
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
how do i convert this into ABAP code .Pls help. Thanks...
the data might be like
NAME DIVISION AMOUNT
ABC IT 400
DEF BPO 500
HTG IT 400

Hi,
You can run an excel macro like this
CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
Call Method of h_excel 'WORKBOOKS' = h_mapl.
set property of h_excel 'VISIBLE' = 0.
Call Method of h_mapl 'OPEN'
EXPORTING
#1 = d_file.
CALL METHOD OF H_EXCEL 'ActiveWorkbook' = h_book .
CALL METHOD OF H_book 'Activesheet' = H_sheet .
CALL METHOD OF h_excel 'RUN'
EXPORTING
#1 = ld_macro.
Check the links below as well
http://sample-code-abap.blogspot.com/2009/07/controlling-excel-using-ole-automation.html
http://arthur_ong.tripod.com/xab017.htm

Similar Messages

  • Translating an excel macro to ABAP

    Hi Guys,
      My requirement is need to put the subtotaling option w.r.t divison when i download the file to an excel sheet via OLE.
    Iam able to get the records in the excel sheet but unable to write the macro in ABAP code.
    the macro which i recorded in Excel is
    Range("A1:C3").Select
        Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3), _
            Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    how do i convert this into ABAP code .Pls help. Thanks...
    the data might be like
    NAME  DIVISION   AMOUNT
    ABC     IT              400
    DEF      BPO         500
    HTG     IT              400

    Hi,
    You can run an excel macro like this
    CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
    Call Method of h_excel 'WORKBOOKS' = h_mapl.
    set property of h_excel 'VISIBLE' = 0.
    Call Method of h_mapl 'OPEN'
    EXPORTING
    #1 = d_file.
    CALL METHOD OF H_EXCEL 'ActiveWorkbook' = h_book .
    CALL METHOD OF H_book 'Activesheet' = H_sheet .
    CALL METHOD OF h_excel 'RUN'
    EXPORTING
    #1 = ld_macro.
    Check the links below as well
    http://sample-code-abap.blogspot.com/2009/07/controlling-excel-using-ole-automation.html
    http://arthur_ong.tripod.com/xab017.htm

  • How to upload an excel file using ABAP.

    Hi,
    Can anyone please help me in understanding how to upload an excel file using ABAP.
    Thanks!!

    http://diocio.wordpress.com/2007/02/12/sap-upload-excel-document-into-internal-table/
    check the link
    TYPES: Begin of t_record,
    name1 like itab-value,
    name2 like itab-value,
    age   like itab-value,
    End of t_record.
    DATA: it_record type standard table of t_record initial size 0,
    wa_record type t_record.
    DATA: gd_currentrow type i.
    *Selection Screen Declaration
    PARAMETER p_infile like rlgrap-filename.
    *START OF SELECTION
    call function ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
    exporting
    filename                = p_infile
    i_begin_col             = ‘1′
    i_begin_row             = ‘2′  “Do not require headings
    i_end_col               = ‘14′
    i_end_row               = ‘31′
    tables
    intern                  = itab
    exceptions
    inconsistent_parameters = 1
    upload_ole              = 2
    others                  = 3.
    if sy-subrc <> 0.
    message e010(zz) with text-001. “Problem uploading Excel Spreadsheet
    endif.
    Sort table by rows and colums
    sort itab by row col.
    Get first row retrieved
    read table itab index 1.
    Set first row retrieved to current row
    gd_currentrow = itab-row.
    loop at itab.
      Reset values for next row
    if itab-row ne gd_currentrow.
    append wa_record to it_record.
    clear wa_record.
    gd_currentrow = itab-row.
    endif.
    case itab-col.
    when ‘0001&#8242;.                              “First name
    wa_record-name1 = itab-value.
    when ‘0002&#8242;.                              “Surname
    wa_record-name2 = itab-value.
    when ‘0003&#8242;.                              “Age
    wa_record-age   = itab-value.
    endcase.
    endloop.
    append wa_record to it_record.
    *!! Excel data is now contained within the internal table IT_RECORD
    Display report data for illustration purposes
    loop at it_record into wa_record.
    write:/     sy-vline,
    (10) wa_record-name1, sy-vline,
    (10) wa_record-name2, sy-vline,
    (10) wa_record-age, sy-vline.
    endloop.

  • How to translate the key words in ABAp program from lower case to upper cas

    How to translate the key words in ABAp program from lower case to upper case?

    Hi Kittu,
    You need to set the Pretty Printer settings to achieve key words in ABAP program from lower case to upper case.
    Utilities -> Settings -> Pretty Printer (tab) -> Select third radio button.
    Thats all.
    <b>Reward points if this helps.
    Manish</b>

  • How to generate new perner number using Abap Code in pa0002. what is the fu

    how to generate new perner number using Abap Code in pa0002. what is the function Module used.

    hi
    define internal number ranges for ur implementation then when u run PA 40  do not input any employee number , system will generate the employee number automatically.
    Regards
    sameer

  • How to Stop at Source System's Abap Code from BI Infopackage Trigger

    Hi Experts,
    I have enahanced 2 fields to some standard data source, that fields data is comiong fine to RSA3 in Source system.
    i am not getting 2 fields data to BI  PSA, but that 2 fields data  i am getting at in RSA3 Tcode  source system.
    i have tried all the ways to get data to BI PSA, but no luck.
    so, while running infopacke from BI i need to stop  at  Source System's Abap code where i have wriiten the code for those 2 fields.
    so, please any  one can explain, how to stop at source system's Abap Code once i  trigger infopackage from BI.
    Regards,
    Nagaraju K.

    Hi,
    which data source on your working?
    master data or transaction data
    enter the TCODE- CMOD
    choose the project
    select the funciton exit - EXIT_SAPLRSAP_001 - Transaction data
                                        EXIT_SAPLRSAP_002 - master data attr
                                        EXIT_SAPLRSAP_003 - mster data text
                                        EXIT_SAPLRSAP_004 - master data hier.
    choose the include program - ZXRSAU01.
    go to source code tab -> go to change mode -> find the code will start form here
    EX- : when " ZLIS_13_VDITM
    if not required don't put break-point .
    just comment it code.
    Thanks,
    Phani.

  • Translate Excel Macro to Abap

    Hi all,
    I have the following macro recorded in my excel and want to 'translate' it to abap.
    The problem is that though it does not give any error and not sy-subrc <> 0 don't works well.
    When I select the cells to which I have put a name,  this name does not appear, if I execute the macro from the excel yes it works well.
    This is the macro;
    ActiveWorkbook.Names.Add Name:="nums", RefersToR1C1:="=Hoja1!R3C1:R8C1"
    Though also it works this way;
    ActiveSheet.Names.Add Name:="nums", RefersToR1C1:="=Hoja1!R3C1:R8C1"
    And this de abap code;
    CREATE OBJECT application 'Excel.Application'.
    CALL METHOD  OF application  'Workbooks' = workbooks.
    CALL METHOD  OF workbooks     'Add' = workbook.
    SET PROPERTY OF application 'Visible' = 0.
    GET PROPERTY OF application 'ACTIVESHEET' = worksheet.
    SET PROPERTY OF worksheet 'Name' = 'Unidades'.
    *....fill cells...
    *Option 1;
    CALL METHOD OF application 'ActiveWorkbook' = o_workbook.
    CALL METHOD OF o_workbook 'names' = o_names.
    *Option 2;
    *CALL METHOD OF application 'ActiveSheet' = worksheet.
    *CALL METHOD OF worksheet 'names' = o_names.
    CALL METHOD OF o_names 'Add'
        EXPORTING
          #1 = 'nums'
          #2 = 'Unidades!R3C1:R8C1'.
    The problem is to instantiate the object o_name.  after "CALL METHOD OF o_workbook 'names' = o_names" if in debbuging I do double-click on the variable, it is empty.
    any idea?
    Thanks in advance.

    I did it !!!
      CALL METHOD OF application 'ActiveSheet' = worksheet.
      CALL METHOD OF worksheet 'Cells' = o_cellstart
        EXPORTING
        #1 = 3
        #2 = 1.
      CALL METHOD OF worksheet 'Cells' = o_cellend
        EXPORTING
        #1 = 184
        #2 = 1.
      CALL METHOD OF worksheet 'range' = range
        EXPORTING
        #1 = o_cellstart
        #2 = o_cellend.
      CALL METHOD OF range 'select'.
    SET PROPERTY OF range 'Name' = 'nums'.

  • Running Excel macros from ABAP

    Hello everyone,
    I am trying to execute an Excel macro from an ABAP program.  We are currently on a 46C system.  While doing some research on help.sap.com I came across the method execute_macro in class i_oi_document_proxy.  I’ve never used methods in ABAP before and I’m not really sure what I’m doing.  Has anyone got this to work?  When I try to run the program it dumps with error OBJECTS_OBJREF_NOT_ASSIGNED.
    Thanks,
    Becky
    Here is the program:
    REPORT ztest_program.
    INCLUDE ole2incl.
    DATA gs_excel TYPE ole2_object .
    DATA gs_wbooks TYPE ole2_object .
    DATA gs_wbook TYPE ole2_object .
    DATA gs_application TYPE ole2_object .
    DATA: h_sheet TYPE ole2_object.
    DATA: document TYPE REF TO i_oi_document_proxy.
    *Name of the macro in Excel
    DATA: macro_string(50) TYPE c
                     VALUE 'FB03process.FromTheBeginning',
          no_flush TYPE c,
          param_count TYPE i VALUE 0,
          script_name TYPE c VALUE 'X',
          error TYPE REF TO i_oi_error
                OCCURS 0 WITH HEADER LINE,
          retcode TYPE soi_ret_string,
          error_string(50) TYPE c,
          retvalue(30) TYPE c.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
       EXPORTING
             text       = text-007
         EXCEPTIONS
              OTHERS     = 1.
    CREATE OBJECT gs_excel 'EXCEL.APPLICATION' .
    SET PROPERTY OF gs_excel 'Visible' = 1 .
    GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooks .
    GET PROPERTY OF gs_wbooks 'Application' = gs_application .
    *--Opening the existing document
    CALL METHOD OF gs_wbooks 'Open' = gs_wbook
         EXPORTING #1 = 'D:\temp\FB03process.xls' .
    tell user what is going on
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
       EXPORTING
              PERCENTAGE = 0
             text       = text-009
         EXCEPTIONS
              OTHERS     = 1.
    GET PROPERTY OF gs_excel 'ACTIVESHEET' = h_sheet.
    CALL METHOD document->execute_macro
         EXPORTING macro_string  = macro_string
                   param_count   = param_count
                   script_name   = script_name
                   no_flush      = no_flush
         IMPORTING error         = error
                   retcode       = retcode
         CHANGING  error_string  = error_string
                   retvalue      = retvalue.
    disconnect from Excel
    FREE OBJECT gs_excel.
    PERFORM err_hdl.
    FORM err_hdl.
      IF sy-subrc <> 0.
        WRITE: / 'Fehler bei OLE-Automation:'(010), sy-subrc.
        STOP.
      ENDIF.
    ENDFORM.                    " ERR_HDL

    Hi,
    Please correct me if I am wrong but it seems that you have not fetched a handle to the document object before issuing the statement CALL METHOD document->execute_macro. Hence the error OBJECTS_OBJREF_NOT_ASSIGNED is being dislayed. If you want to use SAP Desktop Office Integration using ABAP Objects, take a look at this article at http://www.intelligenterp.com/feature/archive/ or http://www.sapinfo.net/public/en/index.php4/article/comvArticle-193333c63b4bd807d2/en/articleStatistic
    Hope this helps.
    Regards
    Message was edited by: Shehryar Khan

  • Run a macro with ABAP code

    Hi everybody,
    Could someone help me finding a way to run a macro of an excel sheet with an ABAP program.
    Explanation:
    - I launch an abap program that opened an excel sheet with that kind of code
    include ole2incl.
    DATA : w_excel   type ole2_object,
               w_books   type ole2_object,
               w_book    type ole2_object,
               w_sheets  type ole2_object,
               w_sheet   type ole2_object,
               w_cell    type ole2_object,
               w_rows    type ole2_object,
               w_font    type ole2_object.
    create object w_excel 'Excel.Application'.
    CALL METHOD OF W_EXCEL 'WORKBOOKS' = W_BOOKS.
    CALL METHOD OF W_SHEET 'CELLS' = W_CELL
           exporting #1 = row
                     #2 = column.
    CALL METHOD OF W_SHEET 'SAVEAS'.
    With my ABAP program:
    - i can open my excel template.
    - i can write and format data inside my excel sheet.
    - i can close and save my excel sheet.
    but i don't how to run the macro that exists in my excel template.
    Thank you in advance.

    Hi,
    Executing Excel Macro from SAP ABAP
    I am populating data in excel sheet using OLE. This excel document contains Macro.
    Is there any way I can start execution of Macro as soon as data is populated in Excel sheet.
    If you are using OLE to populate the Excel Sheet then, then yes you can run a macro.
      CALL METHOD OF OBJ_EX_APP 'Run'
           EXPORTING #1 = MACROSTR.
    Adding a Field Exit
    To add a field exit first find the data element that is linked to the screen field- the screen number and program
    Run program RSMODPRF. You will need to create two function modules one FIELD_EXIT_MEPO_VENDOR and
    FIELD_EXIT_MEPO_VENDOR_A
    FIELD_EXIT_MEPO_VENDOR should have code simply of input = ouput.
    FIELD_EXIT_MEPO_VENDOR_A should have the code for whatever the functionality is required
    Go back to RSMODPRF and run the program without parameters. Use the push buttons to assign the screen, 'A' and program. Use the drop down to activate the field list.
    This should now work, but there is no way of debugging. For further information look at OSS 29377
    program zzdirlist.
    for AIX this method also works.
    DATA: BEGIN OF TABL OCCURS 0,
          TEXT(80) TYPE C,
          END OF TABL.
    DATA: COMMAND(256) TYPE C.
    COMMAND = 'ls'.
    CALL FUNCTION 'RFC_REMOTE_PIPE' DESTINATION 'SERVER_EXEC'
    EXPORTING COMMAND = COMMAND
    READ = 'X'
    TABLES PIPEDATA = TABL.
    LOOP AT TABL.
       WRITE:/ TABL-text.
    ENDLOOP.
    Open the following link,
    http://www.sap-img.com/abap/questions-about-bar-code-printing-in-sap.htm
    Regards,
    Jagadish.

  • How to translate Function text matching to fucntion code?

    I try to translate Function text matching to Function code in GUI status?
    Is there any way you know how to solve it?

    Do you want to get Function code related to function Text in GUI Status programatically?

  • How do i insert excel formula in java code

    Hi frds,
    i want to insert formulas of excel in the excel spredsheet through java code
    eg
    if i want to insert =CONCATENATE(A2,B2) through java code how will i achieve this
    Regards
    JM

    Or [_JExcel_|http://jexcelapi.sourceforge.net/]
    To my knowledge JExcel is more complete and less buggy than POI.

  • How to call method excel subtotal in ABAP program

    I'm trying to call excel method subtotal, but i get an error (sy-subrc <> 0). How to correctly call this method? One of the parameters is an array. I've tried to use an internal table as the array, but ABAP syntax checker shows error.

    Hi Vytautas,
    The best way is to start recording a Macro(Tools->Macro->Record New Macro), and then do the operations (like entering data into cells, summing up, calculations,etc...)
    once you are done, display the macro and you will find all the needful information regarding what metohds are to be called and how...
    Regards,
    Raj

  • How to implement this calendar function in ABAP code

    Hi everyone,
    Our requirement is : Give a date (e.g. YYYY.MM.DD, 1983.12.26), then we need to know which weekday it is. Is there a existing FM for this fuction? or how to implement it in ABAP?
    Thanks a lot for any hint
    Best regards
    Deyang

    Hi Deyang Liu,
        Could you please check these the below links they would give you some idea ....[SAP Calendar Control|http://help.sap.com/printdocu/core/print46b/en/data/en/pdf/BCCICALENDAR/SAP_KALENDER.pdf]
    [Calendar functions |http://help.sap.com/saphelp_nw04/Helpdata/EN/2a/fa00f6493111d182b70000e829fbfe/content.htm]
    [SAP Functions|http://abap4.tripod.com/SAP_Functions.html]
    [Determine calendar |http://help.sap.com/saphelp_nw04/helpdata/en/2a/fa00e9493111d182b70000e829fbfe/content.htm]
    Regards,
    S.Manu

  • How to do scheduled SFTP through an ABAP code

    Hi All,
    i have a scenario like this:
    XI -> Firewall -> UNIX machine <- 3rd PARTY.
    Since 3rd parties are putting their files on UNIX machine, so after UNIX machine there is a firewall so that the 3rd parties cant access the XI machine.
    Since firewall is there, so i cant do normal FTP to get files from UNIX to XI....Moreover it is client requirement to do SFTP to get files from UNIX to XI.
    So i have to do SFTP to get the files from UNIX machine.Moreover i have to bring the files at a scheduled time on weekly basis.
    i have seen the SAPFTP function module in SE37.
    <b>i have to write an ABAP program to do this scheduled SFTP to get the specified files at scheduled times only.</b>
    Can anybody suggest how to do this thing.
    Thanks,
    Rajeev Gupta

    Hi All,
    according to SAP note, SFTP can be achived by using SAPFTP over SSH. it then says that communication via SSH can be configured for both active and passive mode of FTP communication.
    <b>Can anybody tell how to configure communication via SSH for both active and passive mode of FTP communication.</b>
    Because after the above is done, then i think that SAPFTP will use SSH for secure FTP.
    <b>Can anybody also tell how to install SSH client local to client system and SSH demon local to FTP server system.</b>
    Thanks,
    Rajeev Gupta

  • How to reduce the run time of ABAP code (BADI) when it is reading huge data from BPC Cube and thus writing  back huge data to the cube.

    Hi All ,
    In Case of reading huge amount of record from BPC Cube  from BADI code , performing calculations and writing back huge amount of data into the cube , It takes lot of time . If there is any suggestion to read the data  from Cube  or writing data into the cube using some Parallel Processing  methods , Then Please suggest .
    Regards,
    SHUBHAM

    Hi Gersh ,
    If we have a specific server say 10.10.10.10 (abc.co.in) on which we are working, Then under RZ12 we make the following entry  as :
    LOGON GROUP          INSTANCE
    parallel_generators        abc.co.in_10         ( Lets assume : The instance number is 10 )
    Now in SM59 under ABAP Connections , I am giving the following technical settings:
    TARGET HOST          abc.co.in
    IP address                  10.10.10.10
    Instance number          10
    Now if we have a scenario of load balancing servers with following server details (with all servers on different instance numbers ) :
    10.10.10.11   
    10.10.10.13
    10.1010.10
    10.10.10.15
    In this case how can we make the RZ12 settings and SM59 settings such that we don't have to hardcode any IP Address.
    If the request is redirected to 10.10.10.11 and not to 10.10.10.10 , in that case how will the settings be.
    I have raised this question on the below thread :
    How to configure RZ12  and SM59 ABAP connection settings when we have work with Load Balancing servers rather than a specific server .
    Regards,
    SHUBHAM

Maybe you are looking for

  • New Macbook Pro Wont turn after discharge

    Hello everyone, I just purchased my 3rd mac in the past 2 years, yeah that's how hooked I am, now windows free 99% and love it... My brand new macbook pro has a very annoying issue.. if I use it on battery power and it discharges completely I have to

  • Pdfs exported from InDesign CS4 & 5 not displaying or wrongly displaying satin effect

    When I apply satin effect to a text block, it often doesn't display once the file is exported to pdf (using CS4 and Acrobat 8).  Satin effect applied to text or strokes in CS5 don't display fill or stroke color, just the black part of the satin effec

  • How to change generated class name when create binding files.

    I have a dtd file, which has lines like this: <!ELEMENT rights (      %plain-text;      | rights.owner      | rights.startdate      | rights.enddate      | rights.agent      | rights.geography      | rights.type      | rights.limitations      )*>    

  • Why do I have a longer boot time in OS 10.5 than 10.4?

    I have about 50% free disk space. In 10.4 my MacBook Pro went through a full boot procedure (following normal shutdown) only about 1 out of 10 times. Most of the time, there was a quick boot that brought up the desktop after only a few seconds. After

  • View Postings and Messages for Valuation and Translation

    Hi Everyone, Inevitably after valuation (FAGL_FC_VAL) or translation (FAGL_FC_TRANS) is run at month-end and the user exits out of the transaction, questions arise as to how certain items were revalued or translated.  What I'm trying to locate is if