Good day,
Hope someone can help...
I am generating a Word document using inhouse software that has very limited functionality. Luckily, I can call macros using this software but unfortunately, I do not know too much about creating them...
The document I am generating has tables of results which are generated in the system. Users need to be able to add to the document but no change any of the existing tables. I found that I can do this but locking the entire document with something like:
myDoc.Protect wdAllowOnlyReading
How can only do this to the tables?
My plan was to select everything else and then
Selection.Editors.Add wdEditorEveryone
But I dont know how to select all text other than the text in tables.
I could also wrap all the other text in brackets for example {} and then make text editable if between those brackets?
Thanks! Any help would be greatly appreciated!
Thanks to the comments, I was able to use controls to do this fairly easily: Thank you Ike and Charles :)
This is what I ended up with (I think there might be some extra stuff thats not needed but works:) :
Sub LOCKTABLES()
Dim doc As Document
Set doc = ActiveDocument
Dim intCount As Integer
intCount = doc.Tables.Count
Dim iTable As Integer
For iTable = 1 To intCount
Dim source_Table_Range As Range
Set source_Table_Range = doc.Tables(iTable).Range
source_Table_Range.Select
source_Table_Range.ContentControls.Add (wdContentControlGroup)
Selection.ParentContentControl.LockContentControl = True
Next
If ActiveDocument.Saved = False Then ActiveDocument.Save
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.