2
votes

How can I call an excel macro with parameters from ABAP? I've found plenty of references for calling a macro without parameters online using the following method:

CALL METHOD OF obj_ex_APP 'Run' 
   EXPORTING #1 = 'Macro_ID'. 

But I can't find anywhere how to pass the parameter. Thanks for any pointers.

1

1 Answers

4
votes

The arguments/parameters passed to the Macro are specified in consecutive parameters from ABAP.

So let's say you have a trivial macro like the following:

Sub Macro1(value)
    Range("A1").Select
    ActiveCell.FormulaR1C1 = value
End Sub

Then the corresponding code to call the Macro from ABAP will be

call method of excel 'Run'
  exporting #1 = 'Macro1'
            #2 = 'Wassup'. "<- Argument to the 'value' parameter

The only bump you might hit is that you can pass a maximum of 9 parameters to an OLE call from ABAP (correct me if I am wrong), while the Run method allows you to specify 30 parameters for a Macro, so you are left with 8 parameters you can pass to the macro.

For more info, see http://msdn.microsoft.com/en-us/library/office/ff197132.aspx