check if excel file is saved or not

Add-in Express™ Support Service
That's what is more important than anything else

check if excel file is saved or not
i want to check if file is saved. if not save it on desktop 
Yossi Mazal Tov


Guest


on win 7 64bit with office 2010 32bit
i tryed

LCID := LOCALE_USER_DEFAULT;
fAccessMode := 0;

Result := ExcelApp.ActiveWindow.Application.ActiveWorkbook.Get_FullName(0);
IF not ExcelApp.ActiveWindow.Application.ActiveWorkbook.Saved[LCID] then
begin
if FileExists(Result) then
begin
ExcelApp.ActiveWindow.Application.ActiveWorkbook.Save(LCID);
end
else
begin
OfficePassWord := 'DeskTop';
AppVersion := String(ExcelApp.Application.Version[LCID]);
NewFile := RemoveBackSlashChar(GetDeskTopDir) + '\HanibaalTempFile-' +
FormatDateTime('yyyy-mm-dd-hh-nn-ss',now);
if IsIt_X_File(AppVersion) Then
NewFile := NewFile + '.xlsx'
else
NewFile := NewFile + '.xls';
Result := NewFile;
With ExcelApp.ActiveWindow.Application Do
ActiveWorkbook.SaveAs(NewFile,emptyparam, emptyparam, emptyparam, emptyparam, emptyparam,
fAccessMode, emptyparam, emptyparam, emptyparam, emptyparam, LCID);
end;
end
else
.....

the result for the Saved[LCID] alwase return False (even for LCID := GetUserDefaultLCID)[B]
Posted 25 Jun, 2013 15:40:16 Top
Andrei Smolin


Add-in Express team


Posts: 18826
Joined: 2006-05-11
Hello Yossi,

procedure TAddInModule.adxRibbonTab1Controls0Controls0Click(
  Sender: TObject; const RibbonControl: IRibbonControl);
var
  wnd: Excel2000.Window;
  iWndParent: IDispatch;
  book: Excel2000._Workbook;
begin
  wnd := ExcelApp.ActiveWindow;
  iWndParent := wnd.Parent;
  iWndParent.QueryInterface(IID__Workbook, book);
  if Assigned(book) then begin
    if book.Saved[ExcelApp.LanguageSettings.LanguageID[Office2000.msoLanguageIDUI]] then
      ShowMessage('Saved')
    else
      ShowMessage('NOT saved')
  end;
end;


In Excel 2010-2013, this code produces "Saved" for an existing .xlsx; after modifying the workbook, it produces "NOT Saved". The same occurs for a new unmodified workbook (including that opened by default): the code produces "NOT saved" only after you modify the workbook; a new unmodified workbook is regarded as saved in Excel.

Hope this helps.


Andrei Smolin
Add-in Express Team Leader
Posted 26 Jun, 2013 04:43:26 Top
Yossi Mazal Tov


Guest


Hi Andrei

it not working.
i just the file always :)

if you come up with other soultion please let me now.

thanks.
Posted 26 Jun, 2013 07:10:53 Top
Andrei Smolin


Add-in Express team


Posts: 18826
Joined: 2006-05-11
I don't understand you. In what way it doesn't work? Is there an exception? What code line produces it?


Andrei Smolin
Add-in Express Team Leader
Posted 26 Jun, 2013 07:52:41 Top
Yossi Mazal Tov


Guest


when i change some data in sheet and the user click on the button i add.
i want to save the file and do some thing.

the lines you suggest dose not work fine.

in win7 64bit with Office 2010 32bit the check of saved yes/no always return true (even if it not saved).

so i dont no if to save the file and....

(at the end of the process the file is closed)
Posted 26 Jun, 2013 08:54:52 Top
Andrei Smolin


Add-in Express team


Posts: 18826
Joined: 2006-05-11
Do you test a workbook containing some formulas? If so, create a new workbook, enter some value to a cell, save it and check if my code works.


Andrei Smolin
Add-in Express Team Leader
Posted 26 Jun, 2013 08:57:47 Top
Yossi Mazal Tov


Guest


no need to work with any formula.

auser open excel.
insert 1 to the first cell and then click on my button....

in word :
if not WordApp.ActiveDocument.Saved then

in ppt :

if not PowerPointApp.ActivePresentation.Saved = msoTrue then


in excel it wont work.
Posted 26 Jun, 2013 09:20:04 Top
Andrei Smolin


Add-in Express team


Posts: 18826
Joined: 2006-05-11
Yossi,

I suppose that you start Excel with a new empty workbook opened. As explained, book.Saved returns true in this case. Then you press 1 and immdeiately after this - not moving the selection to any other cell - you check book.Saved and it returns true again. I suppose this is what you call 'wont work': you've entered 1 and the book is still "saved". If so, then this is how Excel behaves:
- the workbook cannot be regarded as modified until the user complete modifying the cell;
- otherwise, the workbook wll be "non-saved" after the user enters 1 and then presses {ESC}
- to complete entering a cell the user can select another cell

Anyway, after you finish modifying a cell, you'll get the SheetChange event.


Andrei Smolin
Add-in Express Team Leader
Posted 26 Jun, 2013 09:41:14 Top
Yossi Mazal Tov


Guest


hiiiiiiiiiii you right.

now even this one work

IF Not ExcelApp.ActiveWindow .Application.ActiveWorkbook.Saved[LCID] then
begin


thanks.

Yossi
Posted 26 Jun, 2013 10:36:37 Top