Skip to Content
-1

Ms word Integration with SAP using OLE methods for Header sections and footer sections (Word.basic)

Hi all ,

I am replacing the MS office Word Data (Place holders) with SAP data using OLE , its working fine ....

But here i am facing Problem with Header and footer .

in my word document i have different Header sections and footer sections .

I am using Call method of gs_word 'ViewHeader'.

Call Method of gs_word 'Editreplace'

methods for repainting data .

But data is not replacing if the header section will change , kindly let me know any method is there for finding the different header sections and footer sections.

Urgent ....

Regards .

Hemanth

Add comment
10|10000 characters needed characters exceeded

  • By the way, there's also a Word generator -> Generate DOCX file in ABAP

  • Hi Sandra ,

    Here i created macro for Find replace .

        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "#VOID$1"
            .Replacement.Text = "Hemanth"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    

    For above Macro i developed ABAP code as below.

    CALL METHOD OF word 'ActiveWindow' = w_activewindow.
    CALL METHOD OF w_activewindow 'ActivePane' = w_activepane.
    CALL METHOD OF w_activepane 'View' = w_activeview.
    *--Getting applications handle
    GET PROPERTY OF actdoc 'application' = application .
    GET PROPERTY OF application 'Selection' = selection.
    * GET PROPERTY OF selection 'InlineShapes' = inlineshapes.
    SET PROPERTY OF w_activeview 'SeekView' = '9'.
    * find
    GET PROPERTY OF selection 'find' = find.
    * find text
    SET PROPERTY OF find 'Text' = '#VOID$1'.
    * find text forward
    SET PROPERTY OF find 'Forward' = abap_true.
    * Clear formatting
    CALL METHOD OF find 'ClearFormatting'.
    GET PROPERTY OF find 'Replacement' = oreplacement.
    SET PROPERTY OF oreplacement 'Text' = 'Hemanth'.
    CALL METHOD OF oreplacement 'ClearFormatting'.
    * Replacing
    CALL METHOD OF find 'Execute'
      EXPORTING
        #01 = '#VOID$1'
        #02 = abap_false
        #03 = abap_false
        #04 = abap_false
        #05 = abap_false
        #06 = abap_false
        #07 = abap_true
        #08 = 1
        #09 = abap_false
        #10 = gv_charg
        #11 = 2.

    I am trying to replacing the header sections .

    in my file i have different header sections.

    only first header section (3 pages) is replacing with sap data , remaining is not replacing , kindly correct my code if any changes required.

  • If you find the GoTo command in MS Word, then you can use the macro recorder (Ctrl+G in my Word English version). So, to reach the first section:

    Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=1

    To reach the next section (not via the recorder, deduced from "Which" possible values):

    Selection.GoTo What:=wdGoToSection, Which:=wdGoToNext

    Note: based on the Word Object Browser, I agree that "Replace" is the #11 th parameter:

    Function Execute([FindText], [MatchCase], [MatchWholeWord], [MatchWildcards], [MatchSoundsLike], [MatchAllWordForms], [Forward], [Wrap], [Format], [ReplaceWith], [Replace], [MatchKashida], [MatchDiacritics], [MatchAlefHamza], [MatchControl]) As Boolean

    A limit with OLE in SAP is that all "previous" parameters need to be passed (1 to 10 in your case). So it's okay that you added the 10 first parameters.

    But now, your ABAP code has lots of redundancies, as you can see (VBA equivalence):

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection
            .Find.Text = "#VOID$1"
            .Replacement.Text = "Hemanth"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
    Selection.Find.Execute _
          FindText:="#VOID$1", _
          MatchCase:=False, _
          MatchWholeWord:=False, _
          MatchWildcards:=False, _
          MatchSoundsLike:=False, _
          MatchAllWordForms:=False, _
          Forward:=True, _
          Wrap:=wdFindContinue, _
          Format:=False, _
          ReplaceWith:="Hemanth", _
          Replace:=wdReplaceAll
    

    All the "With" group can be removed, just make sure it still works by editing the macro and run it:

        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        Selection.Find.Execute _
          FindText:="#VOID$1", _
          MatchCase:=False, _
          MatchWholeWord:=False, _
          MatchWildcards:=False, _
          MatchSoundsLike:=False, _
          MatchAllWordForms:=False, _
          Forward:=True, _
          Wrap:=wdFindContinue, _
          Format:=False, _
          ReplaceWith:="Hemanth", _
          Replace:=wdReplaceAll
  • Follow
  • Get RSS Feed

0 Answers