Avatar of Keith McElroy
Keith McElroy
 asked on

I have 130 Microsoft Word tables inside bookmarks that need to be restricted from editing.

How can I password protect these bookmarks from editing but allow editing on all the other content
Microsoft Word

Avatar of undefined
Last Comment
Keith McElroy

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
John Korchok

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Keith McElroy

ASKER
This is awesome.  Do I put a password in Password:= or  leave blank?
Keith McElroy

ASKER
I assume I add a macro and run this code, is that how I deploy this?
SOLUTION
John Korchok

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Keith McElroy

ASKER
Thank you this is very helpful!!!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Keith McElroy

ASKER
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:
Sub Unprotect()
    ActiveDocument.Unprotect
End Sub

Open in new window


With a password:
Sub Unprotect()
    ActiveDocument.Unprotect Password:="blahblahblah"
End Sub

Open in new window


Unless you add new tables and text sections, the document is already marked correctly. So to reprotect after data updates, this will work:
Sub Reprotect()
    ActiveDocument.Protect Password:="", Type:=wdAllowOnlyReading
End Sub

Open in new window

Keith McElroy

ASKER
Very interesting, wow and thank you!!!!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.