Skip to Content
author's profile photo Former Member
Former Member

Landscape mode word of the OLE

Hello,

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

Thank you!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 09, 2012 at 08:03 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 09, 2012 at 08:03 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.