How to use VBScript to lock a specific region of a Word document?

Viewed 32

So I want to make a specific part of a Word document read-only using VBScript. The version of Word I am using is from Office 16. How to do this manually (recorded a macro for this to see if I would get a better idea on how to do this) I found here.

I know how to lock the entire document, and know that the following works:

'Protect Document 
objDoc.Protect wdAllowOnlyReading, True, "password"

I saw this question being asked (on an old MS forum), but nothing more than this. Any help with this sort of issue on an example I would appreciate.

1 Answers

While you can't do this using the Protect() method directly the answer appears to be in the Question you linked from the MS Forum.

' Protect Document
objDoc.Protect wdAllowOnlyReading, True, "password"

' Select last paragraph of the document
objDoc.Paragraphs.Last.Range.Select 

' Make an exception for current selection
objWord.Selection.Editors.Add(-1)  ' -1 = everyone

Using the Selection object you can modify the Editors on a protected document selection to "everyone" which unprotects that selection only leaving the rest of the document still protected.

Related