procedure TFrmMain.SpeedButton9Click(Sender: TObject);
Var
StrTemp : String;
ZS : Integer;
Nian, Yue, Ri : Word;
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format: OleVariant;
FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike,
MatchAllWordForms, Forward, Wrap, ReplaceWith, Replace: OleVariant;
SaveChanges, OriginalFormat, RouteDocument: OleVariant;
begin
FileName := ExtractFilePath(ParamStr(0)) + 'DOC/考察材料.DOC';
try
// WordApplication1.Disconnect;
WordApplication1.Connect;
except
Application.MessageBox('连接WORD服务器失败,请确定您已经正确安装。','错误框',MB_OK+MB_ICONSTOP);
Abort;
end;
try
Frmjd := TFrmjd.Create(Self);
//显示进度
Frmjd.ProgressBar1.Max:=100;
Frmjd.Show;
WordApplication1.Visible := False;
WordApplication1.Caption := '干部考察材料';
//参数赋值
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;
//打开文档(摸板)
WordApplication1.Documents.Openold( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );
{Assign WordDocument component}
ItemIndex := 1;
WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex));
{Turn Spell checking of because it takes a long time if enabled and slows down Winword}
WordApplication1.Options.CheckSpellingAsYouType := False;
WordApplication1.Options.CheckGrammarAsYouType := False;
//让Word替换标记字符串要使用WordDocument.Range.Find.Execute:姓名
FindText := '<#XM>';
MatchCase := False;
MatchWholeWord := True;
MatchWildcards := False;
MatchSoundsLike := False;
MatchAllWordForms := False;
Forward := True;
Wrap := wdFindContinue;
Format := False;
ReplaceWith := DM.ADOQryMainXM.Value;
Replace := wdReplaceAll;
WordDocument1.Range.Find.Executeold( FindText, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward,
Wrap, Format, ReplaceWith, Replace );
Frmjd.ProgressBar1.Position := 10;//进度
Frmjd.Update;//进度窗口刷新
这是我以前的代码,没修改和注释就贴上来,希望你能看懂,呵呵