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
Similar Messages
-
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 400Hi,
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 -
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. Ive never used methods in ABAP before and Im not really sure what Im 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_HDLHi,
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 -
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'. -
To upload an Excel macro settings into an ABAP program.
Kindly suggest me if there is any FM in SAP that can read the file with .bas ext containing the Excel macro settings.
As the requirement is to read the macro settings into the SAP program and use these settings for the new Excel sheet that will be created through this program xyz.
thanks in advance.Hi,
Please check the FM : RH_START_EXCEL_WITH_DATA
In the exporting Parameter : macro_name you can give the .bas file name from which the macro is read.
Also check my response in the Thread :
[Downloaded data in Excel from SAP table data to have the macro and control? |Re: Downloaded data in Excel from SAP table data to have the macro and cont]
Cheers,
Remi -
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. -
Execute Infopackage Through BAPI Using Excel Macro (BAPI_IPAK_START)
Hi everyone,
I have a problem when execute infopackage through BAPI using excel macro. I have create a button in macro. When this button is clicked, BAPI for trigger InfoPackage will executed (BAPI_IPAK_START) and this button will disabled.
After this process completely done (traffic indicator for the request is green in update rules), the button will enabled again.
Here the subroutine or pseudocode that i will write :
Private Sub ClickButton()
Begin
1. ThisButton.Activated = False --> Disabled Button
2. Call BAPI/custom Function Module to execute InfoPackage (BAPI_IPAK_START)
4. ThisButton.Activated = True --> Enabled Button
End
The problem is i need some statement like this between statement no 2 and statement no 4
Statement That I Want :
3. Wait Until BAPI Execute Completely
So user can click this button again only after the process is finished completely. I don't know how to do this in macro (in ABAP i know i can use "WAIT ... SECOND"), others said this can be done using event in schedule option at infopackage. Anyone,please help me.
Thank you.
Regards,
Satria BEnter that req number in RSRQ and monitor the load
or right click on the DS - manage - you will req in yellow status which is in progress and you can click on the ...takes you monitor screen
Edited by: Srinivas on Jul 6, 2010 7:51 AM -
Excel macro will not run with OLE
I have an ABAP program which builds an Excel macro with VBA code, downloads the file and inserts it into a new Excel workbook, and then runs the macro to populate the workbook. All of this is being done via OLE functionality.
The process works correctly for 99% of our user community. However, some users are having trouble where when the Run Macro command is executed, the program just hangs and nothing happens.
Here's a snippet of the code:
CREATE OBJECT excel 'EXCEL.APPLICATION'.
Insert macro file into the spreadsheet.
CALL METHOD OF excel 'Modules' = ole_module NO FLUSH.
CALL METHOD OF ole_module 'Add' = ole_newmodule NO FLUSH.
CALL METHOD OF ole_newmodule 'Activate' = ole_activate NO FLUSH.
CALL METHOD OF ole_newmodule 'InsertFile' = ole_insertfile NO FLUSH EXPORTING #1 = macrofile.
FREE OBJECT ole_insertfile NO FLUSH.
FREE OBJECT ole_activate NO FLUSH.
FREE OBJECT ole_newmodule NO FLUSH.
FREE OBJECT ole_module.
Execute the macro(s).
macro_name = 'load_data_zsddxl'.
CALL METHOD OF excel 'Run' = ole_run EXPORTING #1 = macro_name.
FREE OBJECT ole_run.
The automation trace gives me this message (sorry about the formatting):
<26=Automation: CALL METHOD "Run" OF [#12/0x109B0C4C/101/Excel.Application.14]
#0: STRING "load_data_zsddxl"
<26=Automation(Error): CALL METHOD "Run"[DispID=259] OF [#12/0x109B0C4C/101/Excel.Application.14]
#0: STRING "load_data_zsddxl"
IDispatch::Invoke raised exceptionThe remote procedure call failed
<26=Automation(Error):
<26=Automation(Error): ****************************ERROR OCCURED IN MODULE: [Microsoft Excel Application]**********************************************************************************************************************************
<26=Automation(Error): PROGRAM_ID |MODULE_NAME |METHOD_NAME |ERROR DESCRIPTION |VERSION |GUI VERSION |MODULE_PATH |
<26=Automation(Error): **********************************************************************************************************************************************************************************************************************
<26=Automation(Error): Excel.Application.14 |Microsoft Excel Application |Run |The remote procedure call failed |14.0.5138.5000 |Gui Version not found |C:\PROGRA1\MICROS1\Office14\EXCEL.EXE |
<26=Automation(Error): **********************************************************************************************************************************************************************************************************************
<26=Automation(Error):
What's strange is that if after starting Excel I set the property VISIBLE = '1', everything works as expected.
The affected users are running on Windows7 with Excel 2010.
Thanks for any direction you can provide.No, I don't. It's been my understanding that by omitting the "NO FLUSH" from a command, that the accumulated commands are flushed at that point. But I'll give it a try. Willing to try anything at this point.
Thanks. -
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′. First name
wa_record-name1 = itab-value.
when 0002′. Surname
wa_record-name2 = itab-value.
when 0003′. 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. -
Hi Gurus,
What is the exact use of macros in abap-hr.Because in normal abap also these macros are existing , but we will not use these in normal abap programming.So is there any specific reason for using macros in ABAP-HR.
Thanks in advance..
Regards,
Rakesh.This is similar to Logical Database usage. We use LDBs in HR more than in other module. SAP has created many macros that can be used in HR. Ex: you have some macros to make use of when using PNP LDB in your program. Similarly SAP provided macros to read text from PCL1 cluster table. Same thing with reading payroll results. In addition you also can define your own macros in the program and use them in the code.
-
How to call excel macros programmatically in C#?
Hi,
I have a requirement where i need to call excel (2003) macros in C# program. Can anyone help me with a code snippet to do the same?
The excel macro function takes two input parameters? how can the parameters be passed?
Any code snippet to do the same in C# would be helpful.
Thanks.Hey there, Sid. I am tryin gto run your code, but I couldn't even gte it to fire. Here's what I ahve now:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace WindowsFormsApplication2
public partial class Form1 : Form
private void button1_Click(object sender, EventArgs e)
//~~> Define your Excel Objects
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkBook;
//~~> Start Excel and open the workbook.
xlWorkBook = xlApp.Workbooks.Open("C:\\Users\\Ryan\\Desktop\\Coding\\Microsoft Excel\\Work Samples\\Work Samples\\Historical Stock Prices.xlsb");
//~~> Run the macros by supplying the necessary arguments
xlApp.Run("ShowMsg", "Hello from C# Client", "Demo to run Excel macros from C#");
//~~> Clean-up: Close the workbook
xlWorkBook.Close(false);
//~~> Quit the Excel Application
xlApp.Quit();
//~~> Clean Up
releaseObject(xlApp);
releaseObject(xlWorkBook);
//~~> Release the objects
private void releaseObject(object obj)
try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
catch (Exception ex)
obj = null;
finally
GC.Collect();
When I hit the play button nothing happens. When I hot F5 nothing happens. Do you ahve any idea what I'm doing wrong. I'd appreciate any advice with this!!
Thanks!!
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it. -
Import from excel in WD ABAP ALV
Hi,
Is there any ready made component e.g which shows Import data from excel to WD ABAP ALV.
Kindly suggest.
Best Regards
SidSample codes:
"Define the tables according to your import data,
"or just define an structure,
"and then define the internal table
DATA IT_Map type table of ZYFIAccountMapCN.
TYPE-POOLS: truxs.
DATA F_Name(128) type C value 'd:\0927.xls'.
DATA: it_raw TYPE truxs_t_text_data.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
I_LINE_HEADER =
I_TAB_RAW_DATA = it_raw
I_FILENAME = F_Name
TABLES
I_TAB_CONVERTED_DATA = IT_Map
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
Ole excel application from abap
Hi all ,
I an calling one excel application from abap . I don't want to make excel file visible , but insted want to save and close the file , by using method
saveas for excel application and later i want to see the file . file name i want to store in a variable .
eg :
CALL METHOD OF H_EXCEL 'FILESAVEAS' = RC
EXPORTING #1 = filename .
Can it be possible ?
regards,
SAhi
i simpler method will be to use the function modules for this purpose.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
file_name = file_name .
lc_filename = file_name.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = lc_filename
filetype = 'DAT'
TABLES
data_tab = gt_itab.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Fn module F4_filename will prompt for the name of the file to be saved and GUI_DOWNLOAD will save the file.
gt_itab is the internal table containing the data to be stored in excel. -
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> -
Excel macro error after deploying in Weblogic
Halo,
I have written excel macros and it is working fine.
but if the same file if i try to open from hyperlink after deploying in Weblogic server , I get the error
"error occured initializing the VBA libraries.
If Microsoft Visual Basic for Applications (VBA) was not installed, or was set to Install on first use,
(advertised, or set to install on demand) you may receive this error message.
Depending on the mode of installation used and the rights of the user to change current settings,
it is possible to install VBA through Control Panel, Add/Remove Programs, Microsoft Office, Add or Remove
features. If Visual Basic for Applications is not listed as an installable feature of Office, the administrator
of your system may have disabled it so it is impossible for you to install it. If VBA is not installed,
it is impossible to run VBA applications/projects on this computer. "
1. Even though Excel VBA application is installed in my machine , why am i getting this error.??
2. I would like to know is there any way to open the excel file even though if the excel software is not installed in client machine??
Appreciate your help.
Thanks.Hi,
I do not see any reason for this to not work.
Is there any difference between the preferences for RX and RXI. Please go to "edit" -> "Preferences" -> "Security(Enhanced)" and uncheck "Enable protected mode at startup".
Are you able to open any pdf from command line with the same command:
"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" <<PDF_FILE>>
Thanks,
Amish.
Maybe you are looking for
-
MD01- PR not getting generated
Hi, When i am running MRP in MD01,it is showing me : No materials were planned Statistics Materials planned Materials with new exceptions Materials with terminated MRP list Parameters Scope of Planning Plnt
-
Can I use my new scanner in Photoshop x64
I just purchased a Canon MP6150 and would like to use it in Photoshop just as I used to before, that is with very precise settings. The only available interface is Wia support or something and it is frightfully basic. So what can I do? Which software
-
Maximum files size for print orders?
Anyone know the maximum filesize that can be uploaded to iPhoto for printing? Anyone successfully sent a JPEG greater than 10 MB? Anything I try to send that is greater than 10 MB gets 'downsampled' to 10 MB in some unknown way. Thanks in advance. SJ
-
When I go to Firefox, I get this message. "Error: Cookies are disabled. Please enable them and try again. Where do I go to enable the cookies?
-
Why does AI CC 2014 "Welcome Window" contain tutorials demonstrating AI CC not 2014?
This is REALLY confusing. I am relieved to see "smooth tool toggle" has been returned as an option for the Pencil tool in CC 2014, but the "Rebuilt Pencil Tool" video within "Welcome>New Features" is showing an old version that does NOT contain this