<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic OLE2 - Execute word macro in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/ole2-execute-word-macro/m-p/12086459#M1971414</link>
    <description>&lt;P&gt;Dear guys!&lt;/P&gt;
  &lt;P&gt;I develop in ABAP quite but finally I have to deal with OLE now. I have the following problem.&lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt;The download always creates at least the following files:&lt;/P&gt;
  &lt;UL&gt;
   &lt;LI&gt;testreport.dat&lt;/LI&gt;
   &lt;LI&gt;restreport.ini&lt;/LI&gt;
   &lt;LI&gt;testreport.doc&lt;/LI&gt;
   &lt;LI&gt;testreport.dot&lt;/LI&gt;
  &lt;/UL&gt;
  &lt;P&gt;I figured out the the macro is available when I open the DOT file using OLE. But still i can't execute it.&lt;/P&gt;
  &lt;P&gt;Can somebody give me a hint how to execute the macro.&lt;/P&gt;
  &lt;P&gt;Thank you very much!&lt;/P&gt;
  &lt;P&gt;Florian&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;  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.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 Sep 2019 10:57:30 GMT</pubDate>
    <dc:creator>former_member414204</dc:creator>
    <dc:date>2019-09-11T10:57:30Z</dc:date>
    <item>
      <title>OLE2 - Execute word macro</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/ole2-execute-word-macro/m-p/12086459#M1971414</link>
      <description>&lt;P&gt;Dear guys!&lt;/P&gt;
  &lt;P&gt;I develop in ABAP quite but finally I have to deal with OLE now. I have the following problem.&lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt;The download always creates at least the following files:&lt;/P&gt;
  &lt;UL&gt;
   &lt;LI&gt;testreport.dat&lt;/LI&gt;
   &lt;LI&gt;restreport.ini&lt;/LI&gt;
   &lt;LI&gt;testreport.doc&lt;/LI&gt;
   &lt;LI&gt;testreport.dot&lt;/LI&gt;
  &lt;/UL&gt;
  &lt;P&gt;I figured out the the macro is available when I open the DOT file using OLE. But still i can't execute it.&lt;/P&gt;
  &lt;P&gt;Can somebody give me a hint how to execute the macro.&lt;/P&gt;
  &lt;P&gt;Thank you very much!&lt;/P&gt;
  &lt;P&gt;Florian&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;  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.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 10:57:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/ole2-execute-word-macro/m-p/12086459#M1971414</guid>
      <dc:creator>former_member414204</dc:creator>
      <dc:date>2019-09-11T10:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: OLE2 - Execute word macro</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/ole2-execute-word-macro/m-p/12086460#M1971415</link>
      <description>&lt;P&gt;I suggest you create a VBA first. after VBA code work, convert it to abap code.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 08:39:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/ole2-execute-word-macro/m-p/12086460#M1971415</guid>
      <dc:creator>DoanManhQuynh</dc:creator>
      <dc:date>2019-09-12T08:39:13Z</dc:date>
    </item>
  </channel>
</rss>

