次のコードは、 'app'パラメータで指定されたドキュメントを開き、特定のドキュメントが閉じられるまで待機します。これは、Excelブックを開いて別のExcelワークブックを開いている場合を除いて、すべてのドキュメントタイプで正常に機能します。コードは、文書が実際に開いているときに閉じていると考えます。どうすればこの問題を解決できますか?ExcelワークブックがDelphiで終了したときの判断
procedure RunAppAndWAit(a: TApplication; app, par, verb: string);
var
seinfo: tshellexecuteinfo;
exitcode: dword;
begin
fillchar(seinfo, sizeof(seinfo), 0);
seinfo.cbsize := sizeof(tshellexecuteinfo);
with seinfo do
begin
fmask := see_mask_nocloseprocess;
wnd := a.Handle;
lpfile := pchar(app);
lpDirectory := pchar(ExtractFileDir(app));
lpParameters := pchar(par);
lpVerb := pchar(verb);
nshow := sw_shownormal;
end;
if ShellExecuteEx(@seinfo) then
begin
repeat
a.ProcessMessages;
GetExitCodeProcess(seinfo.hprocess, exitcode);
until (exitcode <> still_active) or a.terminated;
end
else
sshowmessage('Unable to open ' + app);
end;
私は最終的にファイルを開くことを試みた。例外が発生した場合、まだクローズしていません。それは動作しますが、私は今少し汚い感じ... –