I'm using Delphi 7 to process mail merge document, the document already created outside delphi and is fixed with merge fields, my goal is to edit (change) those merge field through delphi 7.
Let just say i have merge field named 'field1', i have to edit to make the merge field name 'field2'.
I have tried the following to open and replace (edit) the merge field, but i only get to replace the text, the merge field is actually still the same from before replacement.
procedure openword;
var
WordApp: OleVariant;
begin
WordApp := CreateOleObject('Word.Application');
WordApp.Visible := True;
WordApp.Documents.Open('C:\Test.doc');
end;
procedure editmergefield; //replace
Var
WordApp : OleVariant;
begin
WordApp := GetActiveOleObject('Word.Application');
WordApp.Selection.Find.ClearFormatting;
WordApp.Selection.Find.Replacement.ClearFormatting;
WordApp.Selection.Find.Execute(
'Field1',True,True,False,False,False,False,1,False,'Field2',2);
end;
I have a Word 2007 document containing two mailmerge fields,
Title
andLast_Name
. The following D7 code changes the name of the first of them toFirst_name
.