Application Development 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: 

Landscape mode word of the OLE

Former Member
0 Kudos

Hello,

Does anyone know how to setup the page layout in landscape mode word of the OLE?

Thank you!

4 REPLIES 4

Former Member
0 Kudos

Hello,

Try this

REPORT ysl_ole.

TYPE-POOLS : ole2, abap.

DATA : reg_value TYPE string.



DATA: wordobj TYPE ole2_object,

      wordapp TYPE ole2_object,

      worddoc TYPE ole2_object,

      documents TYPE ole2_object,

      word_version TYPE i,

      version_str(80),

      result TYPE abap_bool,

      xtimes TYPE i,

      line(200),

      xsec(1).



* Start with OLE automation

CALL METHOD cl_gui_frontend_services=>registry_get_value

  EXPORTING

    root                = cl_gui_frontend_services=>hkey_classes_root

    key                 = 'Word.Basic\CurVer'

    value               = ''

  IMPORTING

    reg_value           = reg_value

  EXCEPTIONS

    get_regvalue_failed = 1

    cntl_error          = 2

    error_no_gui        = 3

    OTHERS              = 4.



IF sy-subrc <> 0.

  RAISE ole_error.                "download probelm

ENDIF.



CALL METHOD cl_gui_cfw=>flush.

version_str = reg_value.



SHIFT version_str LEFT BY 11 PLACES.

MOVE version_str TO word_version.



IF word_version < 8.

  CREATE OBJECT wordobj 'Word.Basic'.

ELSE.

  CREATE OBJECT worddoc 'Word.Document'.

  GET PROPERTY OF worddoc 'Application' = wordapp.

  SET PROPERTY OF wordapp 'Visible' = 1.

  GET PROPERTY OF wordapp 'WordBasic' = wordobj.

  CALL METHOD OF wordobj 'FileClose'.

ENDIF.

CALL METHOD OF wordobj 'AppShow'.

PERFORM ole_error USING sy-subrc.



IF word_version > 8.

  GET PROPERTY OF wordapp 'Documents' = documents.

  CALL METHOD OF documents 'Add'.

ELSE.

  CALL METHOD OF wordobj 'FileNewDefault'.

ENDIF.



PERFORM ole_error USING sy-subrc.



CALL METHOD OF wordobj 'ResetPara'.

PERFORM ole_error USING sy-subrc.



CALL METHOD OF wordobj 'TogglePortrait'

  EXPORTING

  #11 = 0.                "Orientation (1 = Portrait)

PERFORM ole_error USING sy-subrc.



CALL METHOD OF wordobj 'FilePageSetup'

  EXPORTING

    #01 = '1'         "

    #02 = '2'         "

    #03 = '1.00'      "Top

    #04 = '0.75'      "Bottom

    #05 = '0.75'      "Left

    #06 = '0.75'.     "Right



PERFORM ole_error USING sy-subrc.



CALL METHOD OF wordobj 'ViewHeader'.

PERFORM ole_error USING sy-subrc.



CALL METHOD OF wordobj 'CenterPara'.

PERFORM ole_error USING sy-subrc.



CALL METHOD OF wordobj 'Insert'

  EXPORTING

  #01 = 'Title'.

PERFORM ole_error USING sy-subrc.



CALL METHOD OF wordobj 'CloseViewHeaderFooter'.

PERFORM ole_error USING sy-subrc.



CALL METHOD OF wordobj 'Font'

  EXPORTING

  #01 = 'Arial monospaced for SAP'.

PERFORM ole_error USING sy-subrc.



CALL METHOD OF wordobj 'FontSize'

  EXPORTING

  #01 = 8.

PERFORM ole_error USING sy-subrc.



CALL METHOD OF wordobj 'Bold'

  EXPORTING

  #01 = 1.

PERFORM ole_error USING sy-subrc.





FORM ole_error USING v_err TYPE sy-subrc.
* error routine

ENDFORM.                    "ole_error

best regards,

swanand

Former Member
0 Kudos

Claudio,

I guess one way to do it is to record and save a Macro in Word to toggle to Landscape,  and then call the macro in your ABAP code. ( word doc --> view -> macros -> Record Macro). Or, you can display the recorded macro to find all the OLE methods used and code the same in your ABAP code without calling the macro. 

Check below sample code to call the Macro... Hope this helps!

INCLUDE ole2incl.

DATA: word TYPE ole2_object,

          doc type ole2_object,

          docc TYPE ole2_object.

CREATE OBJECT word 'WORD.APPLICATION'.

CALL METHOD OF word 'Documents' = doc.

CALL METHOD OF doc 'Add' = docc.

Call your Macro to toggle to Landscape...

CALL METHOD OF word 'RUN' EXPORTING #1 = 'Macro1'.

SET PROPERTY OF word 'Visible' = 1.

CALL METHOD OF docc 'SaveAs' EXPORTING #1 = 'c:\macro.doc'.

CALL METHOD OF word 'Quit'.

Thanks,

VM

0 Kudos

Hello!

None of the options solved the problem.

Now open to a blank page.

Any other alternative?

Thanks.

0 Kudos

It worked for me. Can you provide some more details what the error is and what system version you are on?

regards,

swanand