Set Read Only status on Office File

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

Set Read Only status on Office File
 
Sean Ram




Posts: 27
Joined: 2013-03-13
Is there a way to set a Word, excel and powerpoint file to be read only after the file is already open.

Also, need to remove the read only flag if the file is open and already in read only status.
Posted 15 Aug, 2018 14:58:02 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Sean,

I don't think this is possible to do as the {a document object e.g. Workbook}.ReadOnly property is read only. A usual way to specify the read only status is to use the corresponding parameter of these methods:

- Worлbooks.Open() - https://msdn.microsoft.com/en-us/VBA/excel-vba/articles/workbooks-open-method-excel
- Documents.Open - https://msdn.microsoft.com/en-us/VBA/word-vba/articles/documents-open-method-word
- Presentations.Open - see https://msdn.microsoft.com/library/c19456ba-e5a8-83da-00ae-dd387e38febf%28office.15%29.aspx


Andrei Smolin
Add-in Express Team Leader
Posted 16 Aug, 2018 00:37:50 Top
Sean Ram




Posts: 27
Joined: 2013-03-13
Hi Andrei,

Thanks understood. Is it possible to prevent the SAVE on word, excel, power point files, when the user clicks the save button on the the office apps.

1. For example disable the Save
2 . Capture the before save event and prevent the save itself?

any other alternative?

Please note SAVE AS is ok.
Posted 16 Aug, 2018 06:32:20 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Sean,

You can intercept the *BeforeSave event and cancel it. This will prevent Save, SaveAs, and AutoSave.

To allow SaveAs only (or to disallow Save only), you will need 1) to intercept clicking the Ribbon controls (you'll need to find their IdMso's) and pressing key combinations, and 2) if SaveAs is chosen, to open a custom FileSave dialog (see the Application.FileDialog property; it's available on all these object models), analyze the user choice and invoke or not invoke {document type}.SaveAs().

Some ways of SaveAs'ing cannot be intercepted using this approach and you'll need to hide corresponding BackstageView tabs or groups.


Andrei Smolin
Add-in Express Team Leader
Posted 17 Aug, 2018 01:48:13 Top