Search code examples
vbaexcelbookmarks

Deleting Text At Bookmark Along With The Paragraph Below It


I currently have a code that will delete a bookmark from a word document using the portion of my code displayed below:

For i = LBound(BookMarksToDelete) To UBound(BookMarksToDelete)
    wdDoc.Bookmarks(BookMarksToDelete(i)).Delete
Next i

Based on the snippet above, I was curious to if there was a way for me to recreate this portion in order to delete the text at the bookmark, along with the paragraph underneath it (Word document is in the form Header followed by Paragraph starting on next line)


Solution

  • I found a solution to my issue, the following code snippet will produce the desired result:

    For i = LBound(BookMarksToDelete) To UBound(BookMarksToDelete)
        Set pRng = wdDoc.Bookmarks(BookMarksToDelete(i)).Range
        pRng.MoveEnd wdParagraph, 2
        pRng.Delete
    Next i