【发布时间】:2020-11-05 04:02:05
【问题描述】:
我有一个包含多个 RepeatingSectionItems 的文档。以下代码用于在文档受到保护时删除当前选择。但是,我正在尝试找出如何防止第一个部分被选中,因为如果我删除了第一个重复部分,我将无法将其取回并且它会搞砸一切。
Application.ActiveDocument.Unprotect "green"
'
Set objCC = ActiveDocument.SelectContentControlsByTitle("General").Item(1)
objCC.LockContents = False
objCC.AllowInsertDeleteSection = True
'
Dim CC As ContentControl
If Selection.Information(wdInContentControl) Then
Set CC = Selection.ParentContentControl
If Not CC.Type = wdContentControlRepeatingSection Then
Do Until CC.Type = wdContentControlRepeatingSection
Set CC = CC.ParentContentControl
Loop
End If
'loop through the repeatingsectionitems to find the one that selection is in
Dim rsi As RepeatingSectionItem
For Each rsi In CC.RepeatingSectionItems
If Selection.Range.InRange(rsi.Range) Then
rsi.Delete
Exit For
End If
Next rsi
End If
'
Set objCC = ActiveDocument.SelectContentControlsByTitle("General").Item(1)
objCC.LockContents = True
objCC.AllowInsertDeleteSection = False
'
Application.ActiveDocument.Protect wdAllowOnlyFormFields, Password:="green"
【问题讨论】:
-
这很简单。很抱歉直言不讳,但如果您在获得所有帮助后仍无法自己弄清楚这一点,那么您真的不应该尝试这种性质的项目。
-
您是否注意到当您保护表单时,内容控件变得不可编辑?这是因为传统的 Word 表单是为使用旧版表单字段而非内容控件而构建的。
-
@John Korchok- 我明白了。所以您是说在尝试保护文档时使用旧版表单比使用内容控件更好?
-
@Timothy Rylatt- 我明白了。好吧,我想我会试着弄清楚。我的意思是我必须从某个地方开始。尽我所能的先生。
-
如果您使用的是内容控件,则适当的保护是使用带有异常(保护区异常)的只读:support.microsoft.com/en-us/office/…