If I should submit this as a separate question, happy to do so.
We are going to run a ProtectTables() when we release this to all the City managers to review then
run UnProtectTables() when it comes back.
That way we can run the vb script automation to populate the tables after the City managers do their mark up of the narratives.
So, would you be able to tell me if I have the below correct?
BTW, the end result looks great and this is opening my eyes to the possibilities with edit protecting.
I have not fully grasped how the ProtectTables() code works but I think I have the basic idea.
There are other aspects that me and my other team member will learn by using this such as how
to deploy the macro without making the document macro enabled.
Thanks, here's the first attempt at UnProtectTables() and happy to repost if you prefer.
Sub UnProtectTables()
Dim oRange As Range
Set oRange = ActiveDocument.Paragraphs(1).Range
'First we process the space between the top of the document and the first table.
With oRange
.SetRange Start:=oRange.Start, End:=ActiveDocument.Tables(1).Range.Start
.Editors.Add wdEditorEveryone
End With
'Then a loop handles the space between each table.
For x = 1 To ActiveDocument.Tables.Count - 1
Set oRange = ActiveDocument.Tables(x).Range
With oRange
.SetRange Start:=ActiveDocument.Tables(x).Range.End, End:=ActiveDocument.Tables(x + 1).Range.Start
.Editors.Remove wdEditorEveryone
End With
Next x
'Finally we process the space after the last table.
Set oRange = ActiveDocument.Tables(ActiveDocument.Tables.Count).Range
With oRange
.SetRange Start:=ActiveDocument.Tables(ActiveDocument.Tables.Count).Range.End, End:=ActiveDocument.Content.End
.Editors.Remove wdEditorEveryone
End With
'Applying protection makes the tables ineditable.
ActiveDocument.Protect Password:="", Type:=wdAllowOnlyReading
End Sub
John Korchok
To unprotect if there is no password, all you need is: