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

OLE2 - Execute word macro

0 Likes
1,363

Dear guys!

I develop in ABAP quite but finally I have to deal with OLE now. I have the following problem.

SAP Standard (Transaction STWB_2 in SolMan 7.2) creates a test report as a word document (file format DOC). Actually we have our custom report that uses the stanard function module. The file is saved in a local folder. Unfortunately it contains a macro (named SAP_CREATE_TESTREPORT). Since we will download so many of these documents we want the macro to be performed automatically. The processed files will be uploaded to a different system after.

The code below opens Word and the give file. But it does not executes the macro. Indeed, when I do not close the application and check the available macros it's missing macro SAP_CREATE_TESTREPORT.

The download always creates at least the following files:

  • testreport.dat
  • restreport.ini
  • testreport.doc
  • testreport.dot

I figured out the the macro is available when I open the DOT file using OLE. But still i can't execute it.

Can somebody give me a hint how to execute the macro.

Thank you very much!

Florian

  DATA gs_word TYPE ole2_object.

  CREATE OBJECT gs_word 'Word.Basic.8'.

  CALL METHOD OF gs_word 'AppShow' .

  CALL METHOD OF gs_word 'FileOpen'
    EXPORTING
      #1 = p_file.

  CALL METHOD OF gs_word 'Run'
    EXPORTING
      #1 = 'SAP_CREATE_TESTREPORT'.

  CALL METHOD OF gs_word 'FileSave'.

  CALL METHOD OF gs_word 'FileCloseAll'
    EXPORTING
      #1 = 2.

  CALL METHOD OF gs_word 'AppClose'.

  FREE OBJECT gs_word.
1 REPLY 1
Read only

DoanManhQuynh
Active Contributor
951

I suggest you create a VBA first. after VBA code work, convert it to abap code.