Word Automation

Hello,

I would like to implement Find&Replace in Word document.

My current code is as follows:

wrdDoc := wrdApp.Documents.Open(WordTemplateFile);

wrdApp.Selection.Find.ClearFormatting();
wrdApp.Selection.Find.Text := ‘AAAAAA’;

wrdApp.Selection.Find.Forward := TRUE;

WrdApp.Selection.Find.Wrap := 1; //wdFindContinue;

wrdApp.Selection.Find.Replacement.ClearFormatting();
wrdApp.Selection.Find.Replacement.Text := ‘BBBBBB’;

wrdApp.Selection.Find.Execute();

wrdApp.Visible := TRUE;

//*

When I execute this code thw word document is opened and cursor position is at first

AAAAAA string (selected inverse).

No replacement is taking place.

What am I doing wrong or missing?

Regards

This is de code i use that works fine:

ltxt_ReplaceBy := ‘BB’;
ltxt_ToSearch := ‘AA’;
lint_Type1 := 1;
lint_Type2 := 1;
lint_Type3 := 1;
ltxt_Type1 := ‘’;
laut_wrdApp.Selection.GoTo(lint_Type1,lint_Type2,lint_Type3,ltxt_Type1);
laut_wrdApp.Selection.Find.ClearFormatting;
laut_wrdApp.Selection.Find.Replacement.ClearFormatting;
lint_Type1 := 1;
lint_Type2 := 2;
laut_wrdApp.Selection.Find.Execute(ltxt_ToSearch,lbln_False,lbln_False,lbln_False,lbln_False,
lbln_False,lbln_True,lint_Type1,lbln_False,ltxt_ReplaceBy,lint_Type2,lbln_False,lbln_False,lbln_False,lbln_False);

Thank you Lambert. Your solution is exactly what I neaded.

Best Regards.