|
-
Feb 4th, 2008, 01:34 PM
#1
Thread Starter
New Member
[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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|