改了一下,希望对楼主有用。
var
a, b, c, App: OleVariant; //添加a, b, c三个无用的临时变量
begin
try
App := GetActiveOleObject('Word.Application');
except
try
App := CreateOleObject('Word.Application');
except
Exit;
end;
end;
App.Visible := false;
if OpenDialog1.Execute then
begin
App.Documents.open(filename:=OpenDialog1.FileName);
App.Selection.Find.ClearFormatting;
App.Selection.Find.Text := '222';
if App.Selection.Find.Execute then
ShowMessage('GOT')
else
ShowMessage('NO');
App.Documents.Application.Quit(a, b, c); //直接退出WORD了
end;
end;