frank-hoffman's avatar
frank-hoffman
Copper Contributor
Feb 23, 2024
Status:
New

Implement Document.Protect and Document.Unprotect in Word JavaScript API

I'm developing an add-in using the Word JavaScript API, and I need the ability to work with protected Word documents programmatically. In VBA and VSTO, I was able to unprotect these documents, alter them, and then protect them again. Please implement the https://learn.microsoft.com/en-us/office/vba/api/Word.document.protect and https://learn.microsoft.com/en-us/office/vba/api/Word.Document.Unprotect methods in Word's JavaScript API so that I don't have to do this through VBA or VSTO. It looks like this was already done in Excel (see https://learn.microsoft.com/en-us/javascript/api/office-scripts/excelscript/excelscript.worksheetprotection?view=office-scripts).

8 Comments

  • mkanorwala's avatar
    mkanorwala
    Copper Contributor

    We are using office.JS add-in and javascript apis of word. 

    Is it technically possible to achieve the following using Office.js in a Word add-in?

    We want to add custom properties (such as document IDs and metadata) to Word documents opened via our add-in. Based on the presence of specific custom properties or keywords, we aim to disable Word's default 'Save,' 'Save As,' and 'Share' options to prevent users from saving or sharing the document locally.

    Additionally, we would like to implement custom protection mechanisms through our add-in. Could you please confirm whether this functionality can be implemented and suggest best practices or limitations we should be aware of?

  • martin-kouba's avatar
    martin-kouba
    Copper Contributor

    Working with the JavaScript API reminds me of working with VBScript. First it's like "hey that's cool" until you realize "**bleep** can't use it at all and have to reimplement with something else".

  • frank-hoffman's avatar
    frank-hoffman
    Copper Contributor

    Sure Yun_Wang. The use case we have here is that we're dealing with a legal document that has protected content sections. The reason for this is so customers don't inadvertently alter other parts of the document that are used in downstream processing. The customers want to have the ability to remove one of the content controls from the document but can't unless we unprotect the document first. In the legacy system there was some VBA that would do this for them. I've seen some other parts of the code that also needed to unprotect the document for other reasons, though I haven't tracked down all the use cases there yet.

  • mrwilson1980's avatar
    mrwilson1980
    Copper Contributor

    This seems like a very basic function that is needed and is missing. Microsoft, please read this and take action.