Skip to Content
0
Former Member
Dec 07, 2011 at 02:02 PM

Exporting data to Microsoft Project 2010

224 Views

Hi everybody,

I have a question concerning the usage of OLE. I found tons of material about how to export data to word and excel with ole, but havent found a single resource that would explain how to export to Microsoft Project 2010.

So basically what I have to do is exporting an ALV table containing a lot of data into MS Project the same way we can do it with Word or Excel. Since I didnt find any other way, I directly called the ole methods of Office which you can find in Office by ALT + F11 -> Object Browser.

I even got the data into my MS Project quite nicely, but there is one small problem which is giving me headaches. When I export my data, it doesnt automatically open MS Project. It generates all the objects in the background, and if I had Office open before exporting, it would work perfectly.

So does anybody have an idea what I'm missing here to get MS Project to generate a new instance of itself and opening my newly exported document afterwards?

  METHOD ole.
    DATA: lr_app      TYPE ole2_object,
               lr_project  TYPE ole2_object.

    "MS Project
    CREATE OBJECT lr_app 'MSProject.Application'.
    CREATE OBJECT lr_project 'MSProject.Project'.

    "Pasting data
    LOOP AT gt_outtab INTO gs_outtab.

      "Task Name
      CALL METHOD OF lr_app 'SelectTaskField'
        EXPORTING
        #1 = index
        #2 = 'Outline Level'
        #3 = 'false'.
      CALL METHOD OF lr_app 'SetTaskField'
        EXPORTING
        #1 = 'Outline Level'
        #2 = gs_outtab-outline.


      "Name
      CALL METHOD OF lr_app 'SelectTaskField'
        EXPORTING
        #1 = index
        #2 = 'Name'
        #3 = 'false'.
      CALL METHOD OF lr_app 'SetTaskField'
        EXPORTING
        #1 = 'Name'
        #2 = gs_outtab-bez.


      "Duration
      CALL METHOD OF lr_app 'SelectTaskField'
        EXPORTING
        #1 = index
        #2 = 'Duration'
        #3 = 'false'.
      CALL METHOD OF lr_app 'SetTaskField'
        EXPORTING
        #1 = 'Duration'
        #2 = gs_outtab-bez.


      "Milestone or not?
      CALL METHOD OF lr_app 'SelectTaskField'
        EXPORTING
        #1 = index
        #2 = 'Milestone'
        #3 = 'false'.
    ENDLOOP.

    "Maximize application
    CALL METHOD OF lr_app 'AppMaximize'
      EXPORTING
      #1 = 'true'.

    "Free document
    FREE OBJECT lr_app.

    CALL FUNCTION 'FLUSH'
      EXCEPTIONS
        cntl_system_error = 1
        cntl_error        = 2
        OTHERS            = 3.
    IF sy-subrc <> 0.
    ENDIF.
ENDMETHOD.

Edited by: Cédéric Grieder on Dec 7, 2011 3:02 PM

Edited by: Cédéric Grieder on Dec 7, 2011 3:03 PM