Please help!
Im running the code below as a standalone application and it works just fine!
When I run the exact same code within an Service application the "Error line" below throws exception 'Det går inte att komma åt filen D:\Services\ListServer\Document\SalesCompare.xls. Det kan finnas flera orsaker: • Filnamnet eller sökvägen finns inte. • Filen används av ett annat program. • Den arbetsbok du försöker spara har samma namn som en arbetsbok som redan är öppen'.
Translated this says something like "Can't reach file xxx, there can be different reasons, filename or path missing, file used by Another program, the file you are trying to save is already opened!'
The machine is a Windows 2012 Server R2 Standard.
I use Delphi 10.2 Tokyo.
I tried running the service with both Application.DelayInitialize as True and False, both giving exactly the same result.
I am calling "CoInitialize(Nil);" before this code and "CoUninitialize;" afterwards.
Office version is 2013, Swedish!
I use the same User account when running as a desktop application and when running as a service.
Any ideas?
Function TExcelForm.ExcelInsertText(ExcelFileName: String) : Boolean;
Var ExcelApplication : Variant;
WorkBook : Variant;
FileName: OleVariant;
UpdateLinks: OleVariant;
ReadOnly: OleVariant;
Format: OleVariant;
Password: OleVariant;
WriteResPassword: OleVariant;
IgnoreReadOnlyRecommended: OleVariant;
Origin: OleVariant;
Delimiter: OleVariant;
Editable: OleVariant;
Notify: OleVariant;
Converter: OleVariant;
AddToMru: OleVariant;
Local: OleVariant;
CorruptLoad: OleVariant;
Begin
ExcelApplication := CreateOleObject('Excel.Application');
ExcelApplication.DisplayAlerts := False;
ExcelApplication.Caption := 'ListServer';
ExcelApplication.EnableAnimations := False;
ExcelApplication.EnableAutoComplete := False;
ExcelApplication.Interactive := False;
ExcelApplication.LargeButtons := False;
While ExcelApplication.WorkBooks.Count > 0 Do ExcelApplication.WorkBooks[0].Delete;
FileName := ExcelFileName;
UpdateLinks := 0;
ReadOnly := True;
Format := 4; // Fältseparator vid öppning av fil ;
Password := '';
WriteResPassword := '';
IgnoreReadOnlyRecommended := True;
Origin := xlWindows;
Delimiter := ';';
Editable := False;
Notify := False;
Converter := EmptyParam;
AddToMru := False;
Local := False;
CorruptLoad := xlRepairFile ;
// The Open command belo throws exception !!
WorkBook := ExcelApplication.WorkBooks.Open(FileName,UpdateLinks,ReadOnly,Format,Password,WriteResPassword,IgnoreReadOnlyRecommended,Origin,Delimiter,Editable,Notify,Converter,AddToMru,Local,CorruptLoad);
// Do some stuff here
WorkBook.Close(False);
ExcelApplication := Unassigned;
End;
Connect with Us