我目前有一个代码,可以使用下面显示的代码部分从word文档中删除书签:
For i = LBound(BookMarksToDelete) To UBound(BookMarksToDelete)
wdDoc.Bookmarks(BookMarksToDelete(i)).Delete
Next i
根据上面的代码片段,我很好奇是否有一种方法可以让我重新创建这个部分,以便删除书签中的文本及其下面的段落(Word文档的格式为Header,后跟段落从下一行开始)
答案 0 :(得分:0)
Dim whattokill As Range
For i = LBound(BookMarksToDelete) To UBound(BookMarksToDelete)
With wdDoc.Bookmarks(BookMarksToDelete(i))
Set whattokill = .Range
whattokill.Expand wdParagraph
'repeat above line if you want more than one para
whattokill.Delete
End With
Next i
答案 1 :(得分:0)
我找到了解决问题的方法,以下代码段将产生所需的结果:
For i = LBound(BookMarksToDelete) To UBound(BookMarksToDelete)
Set pRng = wdDoc.Bookmarks(BookMarksToDelete(i)).Range
pRng.MoveEnd wdParagraph, 2
pRng.Delete
Next i