Find/Replace Code

D

Don

Hi.........

I would like to be able to write a Macro that selects the
first the current parapraph as well as the one above. If
either of those two paragraphs are a secion break, I would
like to repalce it with nothing.

This code seems to be close, but I think the problem lies
with wdRepalceAll (although I could be wrong). I just
want the code to find/select/replace the two selected
paragraphs and not the entire document. As it stand now,
it does the entire doc. Can anyone see where I am going
wrong? I might want to consider remove the prompt for
wdask as well, so the user is never prompted to check the
rest of the document.

Thanks in Advance,
Don



Sub Macro1()
'
' Macro1 Macro
' Macro recorded 9/11/2003 by Gibbons, Del Deo
'
Selection.EndOf Unit:=wdParagraph, Extend:=wdMove
Selection.MoveUp Unit:=wdParagraph, Count:=2,
Extend:=wdExtend
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^b"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
End Sub
 
L

Larry

Don,

The main thing was that you had Selelction.FindExecute appearing twice,
so I commented out the repeated line. Also, I have it search forward
instead of backward, and use wdFindStop, which stops the search at the
end of the selection. However, this only works if cursor is in the text
paragraph, not of it's located in the section break line.

Larry


Selection.EndOf Unit:=wdParagraph, Extend:=wdMove
Selection.MoveUp Unit:=wdParagraph, Count:=2, Extend:=wdExtend
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^b"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
End With
' Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
 

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