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 Replace Macro - MS Word

Status
Not open for further replies.

richiwatts

Technical User
Jun 21, 2002
180
GB
Hi,

Is there anyone who can help me with a Macro to carry out some find and replace functions.

I have a number of documents and in all of them I need to search and replace the follow. It is taking me ages to do it manually.

--
Find (using wildcards)
\<*\>
Replace (with style name)
Style name = tw4winEx
--
Find (using wildcards)
\<a*\>
Replace (with style name)
Style name = tw4winIn
--
Find (normal)
<b>
Replace (using only a style name)
Style name = tw4winIn
--
Find
Men
Replace with
Women
--


There are more I have to do to each document but only these 4 different variations

Can anyone help?

Thanks

Rich
 
Have you tried to look at the code generated by the macro recorder when you do it manually ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yes, but it is so messy I can't work out how to manually add all the rest and manually change things

Rich
 

Depending on the version of Word, recording may or may not help you. here is some amended recorded code - it isn't really hard to change!
Code:
[blue]With Selection.Find
        
    .Forward = True
    .Wrap = wdFindContinue
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    
    .ClearFormatting
    .Replacement.ClearFormatting
        
    .Text = [red]"\<*\>"[/red] [green]' Change this[/green]
    .MatchWildcards = [red]True[/red] [green]' Maybe change this[/green]
        
    .Replacement.Text = [red]""[/red]  [green]' Change this[/green]
    .Replacement.Style = ActiveDocument.Styles([red]"tw4winEx"[/red]) [green]' Change this[/green]
    .Format = True
    
    .Execute Replace:=wdReplaceAll

    End With[/blue]
Repeat (with appropriate changes) for each change you want to make.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top