ReplaceBookmark

S

steve@mm

I think this error has to do with AutoFormat. If I have a bookmark at the
beginning of a line--then a space--then the next word as:

MyBookMark cannot figure this out.
ReplaceBookMark MyBookMark, "Joe"

I get this: Joecannot figure this out.

If I put two spaces...I get two spaces. Joe cannot figure this out.

How do I get this to work? Do I turn of some AutoFormatting. It has to be
in code because this doc will live on other machines (not just mine)
 
T

Tony Jollans

What is ReplaceBookMark? If this is code of yours, that is the place to look
for the cause of the problem.
 
S

steve@mm

With a capital ...DUH Yes, that was a user defined func I worte, but I
started to "think" it was part of the Word Object model :)

Anyay here is the code I put in ReplaceBookMark

Version1
'Selection.GoTo What:=wdGoToBookmark, Name:=ThisBookmark
'Selection.Delete Unit:=wdCharacter, Count:=1
'Selection.InsertAfter ReplaceText
'
Problem: When the delete happens on the first word in a sentence, Word
moves the remaning sentence all the way left (if 1 space)

Curr Version
Selection.GoTo What:=wdGoToBookmark, Name:=ThisBookmark
Selection.InsertBefore ReplaceText
Selection.GoTo What:=wdGoToBookmark, Name:=ThisBookmark
Selection.Delete Unit:=wdCharacter, Count:=1
'Problem: No Word prepends the ReplaceText ahead of the ThisBookmark and
the delete deletes all. I've tried to do a Selection.MoveLeft 1, which fixes
the prepend issue but now I've got the ReplaceText right up next the word for
the Replaces that are NOT the first word.

When IReplaceText it looks likethat < --------
 
T

Tony Jollans

You are really making it a whole lot more complex than it needs to be. It is
generally better to work with explicit Ranges rather than the Selection and
this statement is what you want:

ActiveDocument.Bookmarks(MyBookMark).Range.Text = "Joe"

If you have a bookmark without any text it will not be deleted by this so,
depending on what your circumstances are you may want to explicitly delete
it.
 

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