Mike Littlewood
asked on
How can I get feedback from excel to my application as to whether a document has been saved or not.
My application opens an excel template and populate cells with data, but now Im interested as to whether or not I can get feedback from excel to show the document created has been saved. What might I be able to do to achieve this?
procedure TMyForm.CreateExcel;
var
oXL, oWB, oSheet: Variant;
begin
// Start Excel and get Application Object
oXL := CreateOleObject('Excel.App lication') ;
oXL.Visible := True;
//Get template workbook
oWB := oXL.WorkBooks.Open(Extract FilePath(A pplication .exename) + Template.xlt');
oSheet := oWB.ActiveSheet;
//Populate fields from database
with Datamodule, IBQuerydo
begin
<Populate cells>
end;
//of Microsoft Excel's lifetime
oXL.Visible := True;
oXL.UserControl := True;
end;
procedure TMyForm.CreateExcel;
var
oXL, oWB, oSheet: Variant;
begin
// Start Excel and get Application Object
oXL := CreateOleObject('Excel.App
oXL.Visible := True;
//Get template workbook
oWB := oXL.WorkBooks.Open(Extract
oSheet := oWB.ActiveSheet;
//Populate fields from database
with Datamodule, IBQuerydo
begin
<Populate cells>
end;
//of Microsoft Excel's lifetime
oXL.Visible := True;
oXL.UserControl := True;
end;
function FileLastModified(const TheFile: string): string;
var
FileH : THandle;
LocalFT : TFileTime;
DosFT : DWORD;
LastAccessedTime : TDateTime;
FindData : TWin32FindData;
begin
Result := '';
FileH := FindFirstFile(PChar(TheFil e), FindData) ;
if FileH <> INVALID_HANDLE_VALUE then begin
Windows.FindClose(FileH) ;
if (FindData.dwFileAttributes AND
FILE_ATTRIBUTE_DIRECTORY) = 0 then
begin
FileTimeToLocalFileTime
(FindData.ftLastWriteTime, LocalFT) ;
FileTimeToDosDateTime
(LocalFT,LongRec(DosFT).Hi ,LongRec(D osFT).Lo) ;
LastAccessedTime := FileDateToDateTime(DosFT) ;
Result := DateTimeToStr(LastAccessed Time) ;
end;
end;
end;
var
FileH : THandle;
LocalFT : TFileTime;
DosFT : DWORD;
LastAccessedTime : TDateTime;
FindData : TWin32FindData;
begin
Result := '';
FileH := FindFirstFile(PChar(TheFil
if FileH <> INVALID_HANDLE_VALUE then begin
Windows.FindClose(FileH) ;
if (FindData.dwFileAttributes
FILE_ATTRIBUTE_DIRECTORY) = 0 then
begin
FileTimeToLocalFileTime
(FindData.ftLastWriteTime,
FileTimeToDosDateTime
(LocalFT,LongRec(DosFT).Hi
LastAccessedTime := FileDateToDateTime(DosFT) ;
Result := DateTimeToStr(LastAccessed
end;
end;
end;
ASKER
The problem is that there is no file to monitor.
I use a template to create the new excel document, which automatically creates another new file with a new name ready to be saved (i.e. you dont re-save the template). This allows me to re-use the template over and over for new documents.
I use a template to create the new excel document, which automatically creates another new file with a new name ready to be saved (i.e. you dont re-save the template). This allows me to re-use the template over and over for new documents.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
monitor the file modified date...