Delete two lines above bookmark - keep bookmark VBA

Sarahmueller

New Member
Joined
May 17, 2020
Messages
24
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello,

I hope you all are well.

I want to write a macro to delete two lines above a bookmark in a word document. So far so good, but the bookmark itself should not be deleted.

I have come up with the following code:

VBA Code:
Sub DeletetwoLinesAboveBookmark1()

    Dim r As Word.Range
    Set r = ActiveDocument.Bookmarks("Bookmark1").Range
    r.MoveStart wdSentence, -2
    r.Delete

End Sub


But this macro also deletes the bookmark.

Do you have an idea how to solve this problem?

Best regards and a have nice day,

Sarah
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Macropod

Retired Moderator
Joined
Aug 27, 2007
Messages
3,490
Try:
VBA Code:
Sub DeletetwoLinesAboveBookmark1()
Dim r As Word.Range
Set r = ActiveDocument.Bookmarks("Bookmark1").Range
r.Collapse wdCollapseStart
r.MoveStart wdSentence, -2
r.Delete
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,119,277
Messages
5,577,180
Members
412,773
Latest member
ely6678
Top