K
Karl
D7, Excel 2000
After days, and weeks of dealing with this problem and posting code, I'm
still having the problem that Excel won't completely close down. (I know
this is Delphi code. But I think it's easy enough to follow that maybe
someone will have some ideas.)
There are about 120 workbooks in this loop which are opened and closed
thusly:
// enter 'While' loop
while (there are workbooks to open)
// opens in read only
WBk := FExcel.Workbooks.Open( FileName, False, True,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, LCID);
// read values from 5 named ranges
// then......
WBk.Close( False, EmptyParam, EmptyParam, LCID );
WBk := nil;
end; // exit while loop
// finally
FExcel.Quit;
FExcel := nil; <------- Excel is still listed as a task after this is
executed. How come?
My question is, does anyone have any suggestions as to how I might debug
this problem?
TIA,
Karl
////////////////////
procedure TdmPortMan.GetModelData;
var
LCID: integer;
WBk: _Workbook;
FExcel: _Application;
I: Integer;
FileName: String;
ModelData: Variant;
begin
FExcel := CoExcelApplication.Create;
LCID := GetUserDefaultLCID;
adoTBLSecurityMaster.First;
while NOT( adoTBLSecurityMaster.Eof ) do begin
if (adoTBLSecurityMaster.FieldByName( 'ModelWorkbook' ).Value = Null )
then begin
adoTBLSecurityMaster.Next;
Continue;
end;
FileName := FExcelWorkingDirectory +
adoTBLSecurityMaster.FieldByName( 'ModelWorkbook' ).Value + '.xls';
if ( NOT( FileExists( FileName ) ) ) OR
( adoTBLSecurityMaster.FieldByName( 'Status' ).Value =
KInactiveStatus ) then begin
adoTBLSecurityMaster.Next;
Continue;
end;
// opens in read only
WBk := FExcel.Workbooks.Open( FileName, False, True,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, LCID);
adoTBLSecurityMaster.Edit;
try
ModelData := WBk.Names.Item( {'pm'} EmptyParam, 'pm' {EmptyParam},
EmptyParam).RefersToRange.Value;
except
end;
if NOT( VarIsError( ModelData ) ) then
adoTBLSecurityMaster.FieldByName('pm').Value := ModelData;
ModelData := '';
{...similar constructs as above to read 5 more name ranges...}
WBk.Close( False, EmptyParam, EmptyParam, LCID );
WBk := nil;
Application.ProcessMessages;
adoTBLSecurityMaster.Post;
adoTBLSecurityMaster.Next;
end; // while
FExcel.Quit;
FExcel := nil;
end;
After days, and weeks of dealing with this problem and posting code, I'm
still having the problem that Excel won't completely close down. (I know
this is Delphi code. But I think it's easy enough to follow that maybe
someone will have some ideas.)
There are about 120 workbooks in this loop which are opened and closed
thusly:
// enter 'While' loop
while (there are workbooks to open)
// opens in read only
WBk := FExcel.Workbooks.Open( FileName, False, True,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, LCID);
// read values from 5 named ranges
// then......
WBk.Close( False, EmptyParam, EmptyParam, LCID );
WBk := nil;
end; // exit while loop
// finally
FExcel.Quit;
FExcel := nil; <------- Excel is still listed as a task after this is
executed. How come?
My question is, does anyone have any suggestions as to how I might debug
this problem?
TIA,
Karl
////////////////////
procedure TdmPortMan.GetModelData;
var
LCID: integer;
WBk: _Workbook;
FExcel: _Application;
I: Integer;
FileName: String;
ModelData: Variant;
begin
FExcel := CoExcelApplication.Create;
LCID := GetUserDefaultLCID;
adoTBLSecurityMaster.First;
while NOT( adoTBLSecurityMaster.Eof ) do begin
if (adoTBLSecurityMaster.FieldByName( 'ModelWorkbook' ).Value = Null )
then begin
adoTBLSecurityMaster.Next;
Continue;
end;
FileName := FExcelWorkingDirectory +
adoTBLSecurityMaster.FieldByName( 'ModelWorkbook' ).Value + '.xls';
if ( NOT( FileExists( FileName ) ) ) OR
( adoTBLSecurityMaster.FieldByName( 'Status' ).Value =
KInactiveStatus ) then begin
adoTBLSecurityMaster.Next;
Continue;
end;
// opens in read only
WBk := FExcel.Workbooks.Open( FileName, False, True,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, LCID);
adoTBLSecurityMaster.Edit;
try
ModelData := WBk.Names.Item( {'pm'} EmptyParam, 'pm' {EmptyParam},
EmptyParam).RefersToRange.Value;
except
end;
if NOT( VarIsError( ModelData ) ) then
adoTBLSecurityMaster.FieldByName('pm').Value := ModelData;
ModelData := '';
{...similar constructs as above to read 5 more name ranges...}
WBk.Close( False, EmptyParam, EmptyParam, LCID );
WBk := nil;
Application.ProcessMessages;
adoTBLSecurityMaster.Post;
adoTBLSecurityMaster.Next;
end; // while
FExcel.Quit;
FExcel := nil;
end;