[RESOLVED] [Word] wdReplaceOne is not working when searched backward
Hello,
I'm new here and it's been a long time sice I used VB and I have a problem with VB macro in Word. What I am trying to do is to find the last sentence from a paragragh with unknown number of sentences and create a new paragraph. So, I was going to find the last period from the end of a paragraph and replace it with a paragraph marker. However, this code replace all occasions of "period". It works when Forward is set to True, but somehow it doesn't when Forward is set to False. What am I doing wrong?
Here is the code:
' Move to the end of a paragraph
With Selection
.ClearFormatting
.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdMove
.EndOf Unit:=wdParagraph, Extend:=wdMove
.Collapse Direction:=wdCollapseEnd
End With
' Find the last period replace with a paragraph marker
With Selection.Find
.ClearFormatting
.Forward = False
.Text = ". "
.Replacement.ClearFormatting
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceNone
End With
I appreciate any advice.
Re: [Word] wdReplaceOne is not working when searched backward
ta add a paragrapoh at the end of the document, you can try like this
vb Code:
ActiveDocument.Characters(ActiveDocument.Characters.Count).Select
ActiveDocument.Paragraphs.Add
Re: [Word] wdReplaceOne is not working when searched backward
Pete,
Thank you for the post. Though I could not use your code as is, but it lead me to an alternative way to complete the task using Sentences.Last property.