View Single Post
 
Old 01-18-2023, 03:15 PM
dugdugdug dugdugdug is offline Windows 10 Office 2019
Novice
 
Join Date: Jan 2023
Posts: 2
dugdugdug is on a distinguished road
Default Delete text within two bookmarks

Assuming I have the following text:

Code:
Hello,

"BOOKMARK_START"

What are you doing

'BOOKMARK_END"

Call me
I want to delete the text within two bookmarks in Word to end up with:

Code:
Hello,

Call me
I found this code:

Code:
Dim pRange
Dim dRange
Dim myrange

pRange = ActiveDocument.Bookmarks("BOOKMARK_START").Range.Start
dRange = ActiveDocument.Bookmarks("BOOKMARK_END").Range.End
Set myrange = ActiveDocument.Range(Start:=pRange, End:=dRange)
myrange.Cut
What happens when the code is run is BOOKMARK_START and BOOKMARK_END point to the same place, (which is BOOKMARK_START), ie:

Code:
Hello,

BOOKMARK_START / BOOKMARK_END

Call me
Next time I insert something into BOOKMARK_START (and then try to delete it), it won't recognise BOOKARK_END (because it's the same location as BOOKMARK_START).

How can I get round this?
Reply With Quote