Application Development 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: 

Excel Macro with parameters calling from ABAP

Former Member
0 Kudos

Hello experts,

I need to call an Excel Macro from ABAP, I am using  i_oi_document_proxy->execute_macro, but when I execute I dont know how to 'accept' the parameters in my Macro, and to make it even harder for example when I declare parameters in my Macro as below:

Public Sub Macro3(v_start as String, v_end as String)

'

' Macro3 Macro

'

'

    Range("A1:A29").Select

    Selection.Rows.Group

End Sub

The Excel won't recognize my Macro and SAP won't call it

I hope I was clear,

Regards,

Dren

4 REPLIES 4

Former Member
0 Kudos

in the method, I can see the some parameters to pass it to macro? Did you try them already??

Also check this links. May be useful.

roberto_vacca2
Active Contributor
0 Kudos

Hi.

Probably you're calling your Sub in an incorrect way. You must refear always your MainModule in the "name sub parameter".

If you declare a Sub like this

You should not find any problems calling from SAP in this way

           CALL METHOD gr_proxy->EXECUTE_MACRO

             EXPORTING

               MACRO_STRING = 'MainModule.HideSheet'

               PARAM1       = loc_sheetname

               PARAM_COUNT  = 1

             IMPORTING

               ERROR        = gr_error

               RETCODE      = gwf_retcode.


Hope to help


Bye

0 Kudos

Hello Roberto,

This is the Macro I have:

Public Sub Macro1(v_start as String, v_end as String)

'

' Macro1 Macro

'

'

     MsgBox v_start

     MsgBox v_end

    Range("B9:B11").Select

    Selection.Rows.Group

    Range("B9:B12").Select

    Range("B12").Activate

    ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"

    Range("B9:B12").Select

End Sub

This is how I call it from ABAP,


CALL METHOD gc_document->execute_macro

     EXPORTING

       macro_string = 'SAPMain.Macro1'

       param1       = v_start

       param2       = v_end.


As you can see I also used two MsgBox command to see if any data comes from ABAP but it shows nothing,


Can you tell by this what am I doing wrong


Regards,

Dren


0 Kudos

Hi.

Probably you're missing   "   PARAM_COUNT  =  2   "as parameter in the call method.

Try this.

Hope to help

Bye