Brain dead

J

JLenihan

I am working with this macro to have it look through a document for all
italic text and wraps it with <I> and <I*>. If I run it as is, it doesn't do
anything so I am surious what code I put in the find area?

Any help is appreciated

Jerry

Sub ReplItalic()
'
' Replace italic text
' '
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "<I>^&<I*>"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
 
D

Dave Lett

Hi Jerry,

You can use the following:

Sub ReplItalic()
'
' Replace italic text
' '
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "<*>"
.Font.Italic = True
.Replacement.Text = "<I>^&<I*>"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Notice that I changed the .Text parameter (find what) and set the
..MatchWildcards parameter to True.

HTH,
Dave
 
J

J Lenihan

Thanks! Definiately an improvement. The only thing I noticed is that if a
sentence or paragraph is italic it will do each word seperately. Can it find
the beginning and ending of an italic phrase rather than the individual words?

thanks again
 
G

Greg Maxey

Try:

Sub ReplItalic()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Font.Italic = True
.Replacement.Text = "<I>^&<I*>"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
End Sub
 
H

Helmut Weber

Hi J,

.... and I'd suggest to clear all paragraph marks
from any formatting beforehand. Otherwise you might
run into trouble, depending on how you want to process
the output of all the replacing further on.

And take care of removing italic from the replacement
text, so that more runs of your macro don't
result in <I><I><I>some text<I*><I*><I*>

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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