Enable/Disable save button in Word/Excel

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

Enable/Disable save button in Word/Excel
 
Antonio del Pino




Posts: 2
Joined: 2005-07-18
Hi

I put in Word and Excel one button to save document. How can I enable or disable this button when word or excel has or not a active document.

Thanks in advance
Posted 18 Jul, 2005 20:13:00 Top
Dmitry Kostochko


Add-in Express team


Posts: 2742
Joined: 2004-04-05
Hi Antonio,

You can try to handle the OnWorkbookBeforeClose (Excel) and OnDocumentBeforeClose (Word) events to check out the number of documents. If there is one document then you can probably disable your button.
Posted 19 Jul, 2005 04:17:18 Top
Kristjan Hiiemaa




Posts: 27
Joined: 2005-10-29
Im sorry but how to use this event handler? Is there any delphi sample?
Posted 29 Oct, 2005 09:51:26 Top
Dmitry Kostochko


Add-in Express team


Posts: 2742
Joined: 2004-04-05
Hi Kristjan,

See the code below.


procedure TAddInModule.DoAddInInitialize(Sender: TObject);
begin
  if HostType = ohaExcel then
    ExcelApp.OnWorkbookBeforeClose := DoWorkbookBeforeSave;
  if HostType = ohaWord then
    WordApp.OnDocumentBeforeClose := DoDocumentBeforeClose;
end;

procedure TAddInModule.DoWorkbookBeforeSave(ASender: TObject; const Wb: ExcelWorkbook; var Cancel: WordBool);
begin
  // TODO
end;

procedure TAddInModule.DoDocumentBeforeClose(ASender: TObject; const Doc: WordDocument; var Cancel: WordBool);
begin
  // TODO
end;



Posted 30 Oct, 2005 08:41:09 Top
Kristjan H




Posts: 27
Joined: 2005-10-29
Thanks! Really fast answer, it worked well.

But is there also some easy way to enable my button again? Create new event : DoDocumentBeforeOpen??

K
Posted 31 Oct, 2005 02:50:44 Top
Dmitry Kostochko


Add-in Express team


Posts: 2742
Joined: 2004-04-05
Hi Kristjan,

See the OnNewDocument/OnNewWorkbook and the OnDocumentOpen/OnWorkbookOpen events.

Posted 31 Oct, 2005 03:49:45 Top
Kristjan H




Posts: 27
Joined: 2005-10-29
Thank You! Great service.

Kris
Posted 01 Nov, 2005 16:32:27 Top