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

Executing a macro (for WORD)

david_fryda2
Participant
0 Likes
1,659

Hi everyone,

I created a macro in Word.

Now I am calling it successfuly from ABAP using i_oi_document_proxy->execute_macro.

Is there a way to pass a parameter from ABAP to the macro ?

Thanks in advance.

7 REPLIES 7
Read only

Former Member
0 Likes
1,062

hi

hav u seen this FM

<b>IO_OE_TEST_MACRO</b>

<b>RH_START_WWORD_WITH_DATA</b>

Read only

Former Member
0 Likes
1,062

Hi,

Try following logic

INCLUDE OLE2INCL.

DATA EXCEL TYPE OLE2_OBJECT.

DATA WORKBOOK TYPE OLE2_OBJECT.

CREATE OBJECT EXCEL 'Excel.Application'.

CALL METHOD OF EXCEL 'Workbooks' = WORKBOOK.

CALL METHOD OF WORKBOOK 'Open' EXPORTING #1 = 'C:\EX1.XLS'.

Regards

Amole

Read only

Former Member
0 Likes
1,062

Hi David,

You can very well pass parameters from ABAP.

Try this.

CALL METHOD document->execute_macro
EXPORTING macro_string = macro_string
param_count = param_count
no_flush = no_flush
IMPORTING error = error
retcode = retcode
CHANGING error_string = error_string
retvalue = retvalue.

Regards,

Raghav

Read only

Former Member
0 Likes
1,062

Hai David

Check the following Code

DATA: retcode TYPE soi_ret_string VALUE c_oi_errors=>ret_ok.

*

subrc = 0.

*

CALL METHOD proxy->execute_macro

EXPORTING

macro_string = macro_name

param1 = param1

IMPORTING

retcode = retcode

CHANGING

retvalue = retvalue.

IF retcode <> c_oi_errors=>ret_ok.

subrc = 8.

CALL FUNCTION 'HR_BEN_OI_HANDLE_ERROR'

EXPORTING

severity = subrc

reaction = reaction

TABLES

error_table = error_table.

EXIT.

ENDIF.

*

Thanks & regards

Sreenivasulu P

Read only

Former Member
0 Likes
1,062

HI

GOOD

GO THROUGH THIS CODE , I HOPE YOU WILL GET SOME HELP YOU SOLVE YOUR PROBLEM.

----


  • EXAMPLE *

----


REPORT ZVALDATE .

Data: v_date(8).

V_date = '20030102'.

  • VAL_DATE <DATE> <FORMAT> <-- Passing Parameters

val_date v_date 'YYYYMMDD'.

if sy-subrc = 0.

write: 'Valid Date' .

elseif sy-subrc = 1.

write: 'Invalid Date' .

elseif sy-subrc = 2.

write: 'Invalid Date Format' .

endif.

----


  • END OF REPORT *

----


******************************************************

  • To use the macro "VAL_DATE" GLOBALLY, Insert the *

  • below 2 macros in table TRMAC using Txn SM30. *

----


  • Sytax : *

  • VAL_DATA <Date> <Date format>. *

  • It return sy-subrc. *

  • 0 => Valid date - as per the specified format*

  • 1 => Invalid date *

  • 2 => Invalid date format *

  • *

  • <Date format> : *

  • You can pass the following date formats *

  • DDMMYYYY MMDDYYYY YYYYMMDD YYYYDDMM *

----


  • Macro VAL-DATE *

  • This macro validate Date according to the specified*

  • format. *

  • Created by Abhishek Kumar *

  • abhi4r@yahoo.com *

----


define val-dat.

clear: %_date1, %_date2.

%_date1(4) = &1. "Year

%_date1+4(2) = &2. "Month

%_date1+6(2) = &3. "Date

%_date2 = %_date1 - 1.

%_date2 = %_date2 + 1.

if %_date1 <> %_date2.

sy-subrc = 1.

else.

sy-subrc = 0.

endif.

end-of-definition.

----


  • Macro VAL_DATE *

  • Created by Abhishek Kumar *

  • abhi4r@yahoo.com *

----


define val_date.

data %_date1 like sy-datum.

data %_date2 like sy-datum.

data %_date3(8).

case &2.

when 'DDMMYYYY'.

val-date &14(4) &12(2) &1+0(2).

when 'MMDDYYYY'.

val-date &14(4) &10(2) &1+2(2).

when 'YYYYMMDD'.

val-date &10(4) &14(2) &1+6(2).

when 'MMYYYYDD'.

val-date &12(4) &10(2) &1+6(2).

when others.

sy-subrc = 2.

endcase.

end-of-definition.

THANKS

MRUTYUN

Read only

david_fryda2
Participant
0 Likes
1,062

Hi evryone,

Thanks for the help.

But there is still something I cannot perform.

When I pass the parameter to the param1 value of the execute_macro method, I want my macro to receive this param1.

What is the step at the macro level ?

Thanks.

Read only

Former Member
0 Likes
1,062

This is an old question, i know, but for the next one who searches for this topic:

You should just declare a macro in your document (word here) with the parameters.

Public Sub Testmacro(str As String, int1 As Integer)
         MsgBox str         'Display the string
         MsgBox int1        'Display the number
End Sub

you can pass these parameters in their specified order.

greets,

stefan