我有一个包含多个 的文档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"