need to select range based on bookmarks

T

toolmaker

I want the user to be able to select an end-point for a search and replace
range.

After some manipulations, I set the first bookmark like this:

If ActiveDocument.Bookmarks.Exists("myStart") = True Then
ActiveDocument.Bookmarks("myStart").Delete
End If
ActiveDocument.Bookmarks.Add Name:="myStart"

Then I have the user choose an end point, and set the second bookmark:

If ActiveDocument.Bookmarks.Exists("myEndPoint") = True Then
ActiveDocument.Bookmarks("myEndPoint").Delete
End If
ActiveDocument.Bookmarks.Add Name:="myEndPoint"
DeleteRange.DeleteRange

Now I want to select that range, but I haven't been able to do it. I've
tried the following, neither of which work. Any ideas?

Dim myRange as Range
myRange.SetRange Start:=ActiveDocument.Bookmarks("myStart"), _
End:=ActiveDocument.Bookmarks("myEndPoint")
myRange.Select
and

Dim pos1
Dim pos2
Dim r As Range
ActiveDocument.Bookmarks("mystart").Select
Set pos1 = ActiveDocument.Bookmarks("mystart")
ActiveDocument.Bookmarks("myEndPoint").Select
Set pos2 = ActiveDocument.Bookmarks("myendpoint")
pos1.Select
Selection.ExtendMode = True
pos2.Select
Set r = Selection

Thanks for any help you can give me.
 
J

Jezebel

With ActiveDocument
.Range(Start:=.Bookmarks("MyStart").Range.Start,
End:=.Bookmarks("MyEndPoint").Range.End).Select
End with
 
T

toolmaker

Jezebel:

Thanks muchly! I do appreciate the input. I did work out a similar fix
late yesterday. Looks something like this:

myText = Selection
Selection.ExtendMode = False
Selection.MoveLeft Unit:=wdCharacter, Count:=2 ' Move preserves
bookmark

' after a delete function
With ActiveDocument
Set myRange = _
.Range(Start:=.Bookmarks("myStart").Range.End + 1, _
End:=.Bookmarks("myEndPoint").Range.Start)
End With

NOW I've got to work on the Run-Time Error 5854 problem. There is a
work-around, which I haven't yet figured out how to incorporate.

Thanks again: 'toolmaker'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top