BeforeSave Events and ReadOnlyRecommended not working

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

BeforeSave Events and ReadOnlyRecommended not working
Setting ReadOnlyRecommended during AppEvents BeforeSave is not working in Office 2010 
Timo Goebel




Posts: 5
Joined: 2011-05-03
Dear forum,

I wrote a Word/Excel add-in which sets the ReadOnlyRecommended flag of a document/workbook in the BeforeSave event. Up to Office 2003 this worked well. Now I tested the add-in under Office 2010 and found that ReadOnlyRecommended is not set anymore.

The BeforeSave event fires, sets the ReadOnlyRecommended flag (checked during debugging) but as soon as the SaveUI is displayed, the "read only recommended" checkbox (Tools, General Settings) is not checked and the file is saved without the flag.


procedure TAddInModule.adxWordAppEvents1DocumentBeforeSave(ASender: TObject;
  const Doc: _Document; var SaveAsUI, Cancel: WordBool);
var sFileExt: string;
begin
  Doc.ReadOnlyRecommended:=True;
end;


I checked the dll under Office 2003 where it works as expected (the read only recommended flag is set).

Setting HostApp.ActiveDocument.ReadOnlyRecommended to true e.g. by a simple RibbonButton click also works, but that is not the desired result.

Specs: VCL Standard build 758, Delphi 2007, Office Pro Plus 2010 (Version 14.0.5128.5000, 32-Bit), Windows 7 (32-Bit), German OS and Office

Any ideas?

Kind regards

Timo
Posted 03 May, 2011 11:16:24 Top
Dmitry Kostochko


Add-in Express team


Posts: 2839
Joined: 2004-04-05
Hi Timo,

I have just tested your code against Word 2010 and can confirm that the issue exists in that Word version. Right now I can suggest using two TadxRibbonCommand components (IdMso:=FileSave and IdMso:=FileSaveAs) and setting the ReadOnlyRecommended property in their OnAction event handlers:

procedure TAddInModule.adxRibbonCommand2Action(Sender: TObject;
  const Pressed: Boolean; var Cancel: Boolean);
begin
  if (Self.HostType = ohaWord) and (Self.HostMajorVersion = 14) then
    WordApp.ActiveDocument.ReadOnlyRecommended := True;
end;


I have tested the code above, it works fine.
Posted 04 May, 2011 04:46:38 Top
Timo Goebel




Posts: 5
Joined: 2011-05-03
Hi Dmitry,

thank you, this worked!

Kind regards

Timo
Posted 06 May, 2011 07:32:12 Top