Word Select Delete Text Between Two Bookmarks
In this article
To delete text between two bookmarks in Microsoft Word, you use a macro that finds each bookmark, selects the range between them, and deletes it. This article explains the macro code, how to run it, and what to watch out for, plus alternative methods when a macro isn't practical.
Why You Can't Do It Without a Macro
Word's built-in Find and Replace can delete text between two specific characters, but it cannot use bookmarks as boundaries. Bookmarks are invisible markers that store a location or a selected range; they aren't part of the document's text stream that Find and Replace searches. The only built-in way to delete between two bookmarks is to manually select the text with the mouse or keyboard, which is error-prone for long documents. A macro gives you a precise, repeatable method.
The Macro Code
Open the Visual Basic for Applications (VBA) editor by pressing Alt+F11, insert a new module, and paste this code:
Sub DeleteBetweenBookmarks()
Dim bmStart As Bookmark
Dim bmEnd As Bookmark
Dim rng As Range
Set bmStart = ActiveDocument.Bookmarks("StartBM")
Set bmEnd = ActiveDocument.Bookmarks("EndBM")
Set rng = ActiveDocument.Range(bmStart.Range.End, bmEnd.Range.Start)
rng.Delete
End Sub
Replace StartBM and EndBM with your actual bookmark names. The macro creates a range that starts right after the first bookmark and ends just before the second bookmark, then deletes that range. The bookmarks themselves remain in the document.
How to Run the Macro
- Press Alt+F8 to open the Macro dialog.
- Select
DeleteBetweenBookmarksfrom the list. - Click Run.
If you use this often, assign the macro to a button on the Quick Access Toolbar or a keyboard shortcut via File > Options > Customize Ribbon.
What the Code Does Step by Step
Set bmStart = ...gets the first bookmark object.Set bmEnd = ...gets the second bookmark object.ActiveDocument.Range(start, end)creates a range from the end of the first bookmark to the start of the second.rng.Deleteremoves that range's text.
If the bookmarks are in the wrong order (EndBM before StartBM), the range will be invalid and the macro will throw an error. You can add a check to swap them if needed.
Common Problems and Fixes
- Bookmark names contain spaces or start with a number – Word doesn't allow these. Rename bookmarks to start with a letter and use underscores (e.g.,
Start_1). - Bookmark doesn't exist – The macro will error. Use
If ActiveDocument.Bookmarks.Exists("StartBM") Thento check first. - Deleting includes the bookmarks themselves – The code above preserves them. If you want to delete the bookmarks too, add
bmStart.DeleteandbmEnd.Deleteafter the range deletion. - Text between bookmarks is inside a table or text box – The macro works on the main story only. For text boxes, you'd need to iterate through
ActiveDocument.StoryRanges.
Alternatives to a Macro
- Manual selection – Click at the start bookmark, hold Shift, click at the end bookmark, press Delete. Works but imprecise for long spans.
- Find and Replace with wildcards – If your bookmarks are at the start and end of a known phrase, you can use a wildcard pattern like
StartText*EndTextand replace withStartTextEndText. This doesn't use bookmarks but can achieve a similar result. - Using a third-party add-in – Some document automation tools offer bookmark range deletion, but they cost money and may not be necessary.
When to Use This Technique
This macro is useful when you have a template with bookmarks that mark dynamic content – for example, a contract with a variable clause between StartClause and EndClause. You can run the macro to remove the clause entirely before finalizing the document. It's also handy in mail merge scenarios where you need to strip optional sections.
Frequently Asked Questions
Will the macro delete the bookmarks themselves?
No, the code above deletes only the text between them. The bookmarks remain. If you want to delete the bookmarks too, add bmStart.Delete and bmEnd.Delete after the range deletion.
Can I delete text between bookmarks in Word Online?
No, Word Online does not support VBA macros. You would need to use the desktop version of Word to run this macro.
What if the bookmarks are in different sections?
The macro works across sections as long as both bookmarks are in the main document story. If one is in a header or footer, you'll need to modify the code to target that story.
How do I create a bookmark in Word?
Select the location or text, go to Insert > Bookmark, type a name (no spaces), and click Add. You can see all bookmarks in the same dialog.
Is there a way to undo the deletion?
Yes, press Ctrl+Z immediately after running the macro. The macro doesn't affect the undo stack, so a single undo will restore the deleted text.