Title: find and replce in word documents Post by: Stefan S. on April 08, 2015, 12:00:51 pm Hello List,
I try to use wincom to find/replcae I am able to find the string, but I am not able to replace it. Pressing "strg + h" in word I can See my replace.String. Here a word-Macro, which is working (see below): My problem is the last part of the macro: " Selection.Find.Execute Replace:=wdReplaceAll " in the function "suchen_ersetzten" there is call ui.Interface.frontCall("WINCOM","CallMethod", [gl_wwapp,"Selection.Find.Execute", lo_suchen],[gl_wwdoc]) I have to find out how to pass "Replace:=wdReplaceAll" with WinCom commands. Attached a little program. Perhaps anyone has an idea for me. Thanks in advance. Stefan Serwe Sub Makro2() Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "<#ANREDE#>" .Replacement.Text = "Peter Unlustig" .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 Title: Re: find and replce in word documents Post by: Lionel F. on April 09, 2015, 05:50:43 pm Hi Stefan,
I'm afraid we're perhaps facing a WinCom limitation. First, as an information, note that wdReplaceAll refers to a constant....and GDC is only supporting constants on their numeric forms . See also the documentation, especially the "Supported syntax" part: https://4js.com/online_documentation/fjs-gdc-manual-html/?path=fjs-gdc-manual#c_gdc_WinCOM_API.html (https://4js.com/online_documentation/fjs-gdc-manual-html/?path=fjs-gdc-manual#c_gdc_WinCOM_API.html) You'll find in %GDCDIR%\etc\wincom.cst , a list of constants with their corresponding numeric values. This list is not exhaustive, you may find a lot of other constants with their numeric values by searching on the web (The list is now quite old as based on Microsoft Office XP). If we're taking your example, the numeric value referring to wdReplaceAll is 2 (wdReplaceAll=2). So constants must always be replaced by their numeric equivalent in the 4GL code. But in your case this is not the real limitation...perhaps I'm wrong but I'm afraid the problem is that. : Selection.Find.Execute Replace:=wdReplaceAll is a "non parenthesis" notation, which is mentioned as an unsupported notation in the documentation (at the same URL as above). So we'd need to find an equivalent with a parenthesis notation. And unfortunately, from what I tested, Selection.Find.Execute (Replace:=2) doesn't seem to work, at least in Word 2010. A small workaround that works for replacing an occurence would be possibly the following : #First find the text to replace: CALL ui.Interface.frontCall("WINCOM","SetProperty", [wdapp,"Selection.Find.Text", "some text"],[wddoc]) #Execute the search. Text of the search will be selected: CALL ui.Interface.frontCall("WINCOM","CallMethod", [wdapp,"Selection.Find.Execute"],[wddoc]) #Type the text that will replace the other one: CALL ui.Interface.frontCall("WINCOM","CallMethod", [wdapp,'Selection.TypeText("a new text")'],[wddoc]) Now if somebody has a better suggestion, it is really welcome :) Regards, Lionel Title: Re: find and replce in word documents Post by: Stefan S. on April 10, 2015, 08:36:07 am Hello Lionel,
thanks for your workaround. There was still a littel problem iththe "search direction". To search in the whole document I have to set the "Wrap" Option to true in the function "suchen_ersetzen" now It works. Only if the Serach-String is not in the Document the replace-text is placed at the current Text-Position. Thanks and have a nice weekend. Stefan Serwe Code
|