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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

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,118,122
Messages
5,570,313
Members
412,318
Latest member
angoeyuan
Top