Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find and replace with a macro (MS Word)

Status
Not open for further replies.

dcorleto

MIS
May 19, 2002
82
US
Do I need a macro to find/change the following text in Word?

Find...

<paragraph mark><space><space><any lowercase letter>

replace with...

<space><same lowercase letter>

I am baffled by how this might be done, but have a feeling that it is probably do-able with vba...the tough part I think is that I only want it to look for a lowercase letter and disregard uppercase letters or numbers.

Can someone offer some insight...thank you in advance.
 
Can be done, but you gotta try yourself first.

Have you tried recording a macro? Try recording a macro to search for <paragraph mark><space><space><any letter>, and doing a replace. Hint: use the "Special" button on the Find/Replace dialog.

Never mind the lowercase for now. Once you have the first part figured out, post back here.

Gerry
 
I have benn able to successfully do that. That's how I realize that it finds all the lower, uppercase and numbers. My question is how can I make it selectively find only the lowercase? That's not one of the options for the "Special" options in the find/replace dialog box.

I do have the macro recorded....but it doesn't do anything because I only see an other to replace with the same text that's already there....

Sub findlower()
'
' findlower Macro
' Macro recorded 10/21/2004 by Dan
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p ^$"
.Replacement.Text = " ^&"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
End Sub
 
Hi dcorleto,

It is right that you try yourself first and don't come here expecting to have your hand held, but I think Gerry's being a bit hard on you this time - Hi Gerry [smile]

Regular expressions in Word's Find and Replace are not easy. Try checking Use Wildcards, searching for [blue]^13 ([a-z])[/blue] and replacing with [blue] \1[/blue] (that's space backslash one).

When you use wildcards you cannot use ^p for a paragraph mark, and have to use ^13 instead. [a-z] means any character between a and z (they take up a continuous sequence of character codes (97 to 122) in the ascii character set) and enclosing it in parentheses makes it a term you can refer to in the replace part. \1 in the replace means the first parenthesised string in the find part (in this case the [a-z]).

I have no idea (well, I do have an idea, but that's not the point) how this records but I'm sure you can do that bit yourself.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
I have been trying, and get around things by hoook or crook....since the last post, I did find a way, but it is so lengthy, it's easier to just scan the document and do it manually. I know there's an easier way. My way was, after finding that the wildcards won't accept a /p, is to insert a carat character after every /p, and work around the carat to do all the find and replacing, then remove them. It works, but I have to run about 5 macros that I recorded with the recorder in order to make it work - but it does!

I am at that frustrating point of knowing too little, but knowing that it can be done. It makes me nuts....but that's the way I learn I guess.

Thank you so much for responding...
DAN
 
Hi Dan,

Almost every day I am frustrated by finding out just how little I know, too. [smile]

Keep at it!! You do learn by doing it and it is easier next time.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top