替换Word文档中的页眉中的字符串(100)

H

hwsh

Unregistered / Unconfirmed
GUEST, unregistred user!
要将Word中的字符串“<#name>”替换成“delphi”。用了如下程序,但执行后只能替换正文中的数据,但不能替换页眉和页脚中的<#name>请各位给我看看有什么问题。注:我是用word的宏录制后修改而成的。在word中直接用替换命令是可以的,录制成宏后再执行宏就不行了,所以下列程序也不行。procedure TForm1.Button1Click(Sender: TObject);var vWordApp,Tbl:Variant; i:integer; FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace,matchkashida,matchdiacritics,matchAleFhamza,matchcontrol: OleVariant; ItemIndex,FileName,Emp ,fmt :OleVariant ; visible,Template,NewTemplate,DocuType: OleVariant;Begin// NewTemplate:=false;// DocuType:=wdNewBlankDocument;// Visible:=true;// Template:='f:/lx/lx.dot'; //然后使用// wordapplication1.documents.add(Template,NewTemplate,DocuType,Visible); Emp:=EmptyParam; fmt:=0; FileName:='f:/lx/lx.doc'; wordapplication1.documents.Open(FileName,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,Emp,fmt); wordapplication1.Visible:=true; ItemIndex := 1; WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex)); findtext:= '<#Name>'; MatchCase := False; MatchWholeWord := True; MatchWildcards := False; MatchSoundsLike := False; MatchAllWordForms := false; Forward := true; Wrap := wdFindContinue; Format := False; matchcontrol:=false; ReplaceWith:= 'delphi'; Replace := wdReplaceAll; matchkashida:=true; matchdiacritics:=true; matchAleFhamza:=true;// WordDocument1.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageHeader;// WordDocument1.Range.Find.ClearFormatting;// WordDocument1.Range.Find.Replacement.ClearFormatting; worddocument1.range.find.execute( findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike, matchallwordforms, forward, wrap, format, replacewith, replace,matchkashida,matchdiacritics, matchAleFhamza,matchcontrol ) ; end;
 
H

hwsh

Unregistered / Unconfirmed
GUEST, unregistred user!
H

hwsh

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么没有人回答?我是用word的宏录制后修改而成的。在word中直接用替换命令是可以的,录制成宏后再执行宏就不行了,所以下列程序也不行。
 
顶部