Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback. If aDoc.ProtectionType wdNoProtection ThenĪDoc.Protect Type:=wdAllowOnlyRevisions, Password:=strPassword Step 3: Click the top left icon and choose Save. Step 2: Now the Word document is unlocked automatically. Text is inserted, and the document is protected for revisions. Step 1: Right-click the Word document that is locked for editing and chooses to open with WordPad. This example removes protection from the active document. If ActiveDocument.ProtectionType wdNoProtection ThenĪctiveDocument.Unprotect Password:=strPassword This example removes protection from the active document, using the value of the strPassword variable as the password. First, go ahead and open the Word document to be protected and head over to the Review tab.
If the document isn't protected, this method generates an error. How to Lock and Unlock Microsoft word documents 1) first go to MS Office 2) Open a blank document 3) Do or Write whatever you want 4) click to FILE 5) then c.
For recommended best practices on how to do this, see Security notes for Office solution developers. If a password is required in a procedure, request the password from the user, store it in a variable, and then use the variable in your code. Avoid using hard-coded passwords in your applications.