5
我有一個內容控件包含在一個重複節內容控件內的單詞模板。我需要創建一個按鈕來刪除項目中繼器,如添加。通過docx文件的宏中的索引以編程方式刪除重複節項?
我想弄清楚如何刪除重複節項。但在這種情況下 - 我總是刪除最後一個項目。但是,我希望能夠刪除用戶選擇的項目。
Sub delete()
Dim cc As ContentControl
Dim Index
Set cc = ThisDocument.SelectContentControlsByTag("ResolRepeater").Item(1)
With cc
.LockContentControl = False
.LockContents = False
.AllowInsertDeleteSection = True
For Index = 1 To cc.RepeatingSectionItems.Count
If Selection.Range.InRange(cc.RepeatingSectionItems(Index).Range) Or cc.RepeatingSectionItems(Index).Range.InRange(Selection.Range) Then
Exit For
End If
Next Index
'can't delete, get Run-Time Error '5904': "you can not change the range"
cc.RepeatingSectionItems(Index).Range.delete
'this lines always delete last element:
'cc.RepeatingSectionItems(Index).Range.Select
'Selection.Delete
End With
End Sub
我會很樂意回答任何..