Application Development and Automation 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: 
Read only

Execute an Excel Macro?

Former Member
0 Likes
1,230

Hello all,

I created a report in which I show the result in an Excel...so far no problem... I open an Excel Template document, I pass the information I want to the places I want etc. The only problem is that I method for executing a macro seems not to work!

Does somebody has an idea whats wrong?

The security for macros in the excel is at medium...I already tried to put the security level to low...but nothing.

The <i>retcode</i> has as result "MACRO_OR_SCRIPT_FAILED"

I created the Macro and I am sure it works...because when I execute it manualy it does what it should do. Even after my report has open the documente and shows the document I can execute de macro and it works.


        call method p_g_document->execute_macro
          exporting
            macro_string = 'COPYSHEET'
          importing
            error        = it_errors
            retcode      = retcode.

Just for information, the only thing the macro does is copying a spreadsheet.

I somebody could help it would be great, I already lost some days to find the solution.

Thanks in advanced.

Marcelo Moreira

5 REPLIES 5
Read only

Former Member
0 Likes
885

What the Method/FM are you using to export the report output into excel template?

Read only

0 Likes
885

Hi Nagaraju,

To export report output to excel I first of all get the spreadsheet interface, than for each information I want to pass (separatet in blocks) I define a range dimension and then I use this method:


      call method p_g_spreadsheet->insert_one_table
          exporting
                    data_table  = excel_table
                    ddic_name   = 'ZHR_TBORD_HEADER'
                    rangename   = 'SUBAREA'
                    wholetable  = 'X'
          importing
                    error       = it_errors
                    retcode     = retcode.

The <i>excel_table</i> is a table where each line is a caractar line: <i>line(500) type c</i>

Read only

0 Likes
885

Hey all,

Does not seemes that someone has the answer I need, but my last question for this topic is....

Does someone of you already implement a report, using an excel with macro calling from ABAP?

I have doubts if the method

<i>call method I_OI_DOCUMENT_PROXY->execute_macro</i> really work for Excel.

Even in the SAPOFFICEINTEGRATION example I am not sure if it works.

Maybe someone of you has an working example of macro calling from ABAP for Excel.

I would be very glad if somebody has some ideas for my problem....I getting mad with this... :-S

Greetings,

Marcelo Moreira

Read only

0 Likes
885

Can't hurt to look but have you checked your security with Microsoft Excel? In Excel 2000, Macro security may be low but I found with Excel 2003, security defaults to much higher. I lower the Macro security and things begin to work again.

For example, transaction KEPM with Excel 2000 works but if I ALT+TAB, the macro gets confused and causes short dumps. Microsoft is aware of the erro but will not fix it. This caused me to upgrade to Excel 2003 for KEPM Excel in place and it fails due to the Macros involved. I lower the security on Macros in excel and it works great. Excel -> Tools -> Macros -> Security (set to low to prove out the concept)

-Tim

Read only

Former Member
0 Likes
885

Check FM "RH_START_EXCEL_WITH_DATA" also go throught FM's documentation.

Regards

Aman