简体   繁体   English

限制对 Word 表格的编辑

[英]Restricting editing on Word tables

Good day,再会,

Hope someone can help...希望有人可以帮助...

I am generating a Word document using inhouse software that has very limited functionality.我正在使用功能非常有限的内部软件生成 Word 文档。 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我的计划是 select 一切,然后

Selection.Editors.Add wdEditorEveryone Selection.Editors.Add wdEditorEveryone

But I dont know how to select all text other than the text in tables.但我不知道如何 select 除了表格中的文本之外的所有文本。

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 :)多亏了评论,我能够相当容易地使用控件来做到这一点:谢谢 Ike 和 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM