删除书签处的文本及其下面的段落
Deleting Text At Bookmark Along With The Paragraph Below It
我目前有一个代码可以使用下面显示的代码部分从 word 文档中删除书签:
For i = LBound(BookMarksToDelete) To UBound(BookMarksToDelete)
wdDoc.Bookmarks(BookMarksToDelete(i)).Delete
Next i
根据上面的代码片段,我很好奇是否有一种方法可以让我重新创建这部分,以便删除书签处的文本,以及它下面的段落(Word 文档的格式为 Header然后是从下一行开始的段落)
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
我找到了我的问题的解决方案,以下代码片段将产生所需的结果:
For i = LBound(BookMarksToDelete) To UBound(BookMarksToDelete)
Set pRng = wdDoc.Bookmarks(BookMarksToDelete(i)).Range
pRng.MoveEnd wdParagraph, 2
pRng.Delete
Next i
我目前有一个代码可以使用下面显示的代码部分从 word 文档中删除书签:
For i = LBound(BookMarksToDelete) To UBound(BookMarksToDelete)
wdDoc.Bookmarks(BookMarksToDelete(i)).Delete
Next i
根据上面的代码片段,我很好奇是否有一种方法可以让我重新创建这部分,以便删除书签处的文本,以及它下面的段落(Word 文档的格式为 Header然后是从下一行开始的段落)
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
我找到了我的问题的解决方案,以下代码片段将产生所需的结果:
For i = LBound(BookMarksToDelete) To UBound(BookMarksToDelete)
Set pRng = wdDoc.Bookmarks(BookMarksToDelete(i)).Range
pRng.MoveEnd wdParagraph, 2
pRng.Delete
Next i