同意,可以作成域的形式(要输入的地方),然后替换就可以了。这种方式最好(我个人认为)
procedure TForm1.RepalceString;
//让word替换标记字符串要使用worddocument.range.find.execute,这里用delphi替换了<#name>:
var
//一共15个参数
  findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
  matchallwordforms, forward1, wrap, format, replacewith, replace,
  MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl : olevariant; //后四个均为可选项,默认false  num : olevariant;
begin
  findtext := '数据上报操作说明';
  matchcase := false;
  matchwholeword := true;
  matchwildcards := false;
  matchsoundslike := false;
  matchallwordforms := false;
  forward1 := true;
  wrap := wdfindcontinue;
  format := false;
  replacewith := 'delphi';
  replace := true;
  MatchKashida := false;
  MatchDiacritics := false;
  MatchAlefHamza := false;
  MatchControl := false;//  num := 1;
//  WordApplication.Documents.Item(num);
  worddocument.ConnectTo(WordApplication.ActiveDocument);
  worddocument.range.find.execute( findtext, matchcase, matchwholeword,
                                   matchwildcards, matchsoundslike, matchallwordforms,
                                   forward1, wrap, format, replacewith, replace,
                                   matchKashida, MatchDiacritics,
                                   MatchAlefHamza, MatchControl );
end;

解决方案 »

  1.   

    让Word替换标记字符串要使用WordDocument.Range.Find.Execute,这里用Delphi替换了<#Name>: 
    var 
    FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, 
    MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace: 
    OleVariant; 
    begin 
    FindText := '<#Name>'; 
    MatchCase := False; 
    MatchWholeWord := True; 
    MatchWildcards := False; 
    MatchSoundsLike := False; 
    MatchAllWordForms := False; 
    Forward := True; 
    Wrap := wdFindContinue; 
    Format := False; 
    ReplaceWith := 'Delphi'; 
    Replace := True; WordDocument.Range.Find.Execute( FindText, MatchCase, MatchWholeWord, 
    MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, 
    Wrap, Format, ReplaceWith, Replace ); end;