Change Italics to underline

J

Jim Dunavant

I have about 50 files in which italics were used here and there. I need to
replace the italics with underlines. I've spent the last few hours trying
find a way to automate this process (I don't know VBA). What I want to do is
scan an entire document looking for words with italic attribute, and when
found, convert the word to 'regular' and apply the underline attribute. This
process continues until the end of document. Can someone tell me how to do
this, or point me at the instructions?

I'm using Word 2000.

Thanks in advance.

// Jim
 
G

Guest

Hi Jim. You can do a global search and replace on each file:
1. Open a file.
2. Click on Edit | Replace | More.
3. Click on the "Find what" box, then click on Special | Any Character. Click on the Format button in the Find and Replace dialog, then click on Font | Font style: Italic.
4. Click on the "Replace with" box, then on Special | Find What Text. Click on the Format button in the Find and Replace dialog, then click on Font | Font style: Regular | Underline style: <choose one> | Underline color: <choose one>. Check the "Match case" box.
5. Click on Replace All.
6. Save and close the file, open the next file, and start at step 1 again.
 
G

Graham Mayor

Even simpler
Open the replace tool (CTRL+H)
Click in the find what box. Press CTRL+I (italic)
In the Replace with box Press CTRL+I twice (not italic) and CTRL+U
(underline)
Leave both text boxes empty. The formatting shortcuts toggle through the
options they provide.
Replace all.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
L

Larry

Jim,

Here are two macros. With the first, you open each document indivually
and run the macro to make the changes. With the second, all the Word
documents in a named folder will be changed. For instructions on
installing an running a macro (it's not hard), see this web page:

http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm

First macro, to operate on a single document

Sub AllItalicsToUnderline()

With Selection
.Find.ClearFormatting
.Find.Font.Italic = True
.Find.Replacement.ClearFormatting
With .Find
.Text = ""
.Replacement.Text = ""
.Replacement.Font.Italic = False
.Replacement.Font.Underline = wdUnderlineSingle
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Execute Replace:=wdReplaceAll
' Clear Find box
.ClearFormatting
.Replacement.ClearFormatting
End With
End With
End Sub


Second macro, to operate on all documents in a folder
Note: in this macro you've got to alter the sFolder to make it the same
as the
folder you're working on.

Sub ItalicsToUnderlineInFolder()

Dim sFileName As String
Dim sFolder As String

'Replace with your own foldername
sFolder = "C:\Documents\Tests\"
sFileName = Dir(sFolder & "*.doc")

While sFileName <> ""
Documents.Open (sFolder & sFileName)
'run your macro
With Selection
.Find.ClearFormatting
.Find.Font.Italic = True
.Find.Replacement.ClearFormatting
With .Find
.Text = ""
.Replacement.Text = ""
.Replacement.Font.Italic = False
.Replacement.Font.Underline = wdUnderlineSingle
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Execute Replace:=wdReplaceAll
' Clear Find box
.ClearFormatting
.Replacement.ClearFormatting
End With
End With


ActiveDocument.Close savechanges:=wdSaveChanges
sFileName
End Sub

Larry
 
L

Larry

Needless to say, you need to be careful when using this macro. A macro
that can mass-change all documents in a folder can be the computer
equivalent of a weapon of mass destruction. In fact, I keep such macros
in a Word document, only putting them in the VBA code window when I need
them for a specific task, because they're so powerful I don't want even
the possibility of their running accidentally.

Larry
 
S

Suzanne S. Barnhill

The only downside to either of these methods is that if punctuation followed
italicized words has been italicized (as it generally should be), then it
will also be underlined (which it should not be). You may have to search
again for underlined periods, commas, etc., and remove the underline.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

Jim Dunavant

Thanks greatly! Once I understood your instructions correctly, it worked
perfectly.

garfield-n-odie said:
Hi Jim. You can do a global search and replace on each file:
1. Open a file.
2. Click on Edit | Replace | More.
3. Click on the "Find what" box, then click on Special | Any Character.
Click on the Format button in the Find and Replace dialog, then click on
Font | Font style: Italic.
4. Click on the "Replace with" box, then on Special | Find What Text.
Click on the Format button in the Find and Replace dialog, then click on
 
J

Jim Dunavant

Graham,

When I first pressed Ctrl-H I got small simple dialog box titled "Replace"
The two edit boxes beeped at me if I pressed Ctrl+I or U and the replace
buttons remained disabled. I closed the box.

Now if I press Ctrl-H, the normal "Find and Replace" dialog opens with the
"Replace" tab already active, and I did what garfield-n-odie sugested and it
worked.

I tried your instructions in this dialog, and it didn't work. I've idea why.
I'm Word 2000, BTW.

Thanks,
// Jim
--
|| Free Science Fiction Novel
|| "The Keepers of Forever"
|| Read Reviews & Download
|| http://jcd.members.atlantic.net

Graham Mayor said:
Even simpler
Open the replace tool (CTRL+H)
Click in the find what box. Press CTRL+I (italic)
In the Replace with box Press CTRL+I twice (not italic) and CTRL+U
(underline)
Leave both text boxes empty. The formatting shortcuts toggle through the
options they provide.
Replace all.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
<snip>
 
J

Jim Dunavant

Thanks Larry,

I added the single file version to my global template file and it worked
like a champ.

However, the problem Suzanne mentioned about underlining punctuation still
happens. Do you think there is a way to prevent this?

Thanks again,

// Jim
 
L

Larry

Here's a macro (actually two macros, the second is run from the first)
that I developed a while ago (with help from MVPs) for just that
purpose! You could run this on each document, or combine this with the
"all folders in a document" macro that I gave you.

Larry

Sub UnderlineRetract()

' by Larry

' Removes underlining from any space or punctuation after and before
underlined text.
' This ran jerkily, so with Jay Freedman's help it's been rewritten
' to use only range object and not selection.
' Additional code below removes underlining preceding underlined text.

Dim myrange As Range, r As Range
Set myrange = ActiveDocument.Range
Set r = Selection.Range
Application.ScreenUpdating = False
System.Cursor = wdCursorNormal


With myrange.Find
.ClearFormatting
.Font.Underline = wdUnderlineSingle
.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True

Do While .Execute
' myRange.Select
With myrange
.Move wdCharacter, 1
.Select
' myRange.Select
.MoveStartWhile cset:=" " & "," & ":" & "." & "-" & Chr(30) &
Chr(13) _
& "!" & "?" & ")" & ";" & """", Count:=wdBackward

If .Characters.Count > 0 Then .Font.Underline = wdUnderlineNone

' This prevents endless repetition if final para mark in doc is
underlined
If .End >= ActiveDocument.Content.End - 1 Then GoTo Goodby

' Collapse the range to its endpoint before starting the next .Execute.
' Without this, the macro just works on the first underline, then stops.
' I've stepped through this, and don't understand why it stops, since
the
' range is now in the space AFTER the remaining underlining of the word,
so it
' should simply find the next underlining, but that's not what happens.
In any
' case, the macro works beautifully now.

.Collapse wdCollapseEnd
End With
Loop
End With
Goodby:
'Clear Find parameters
myrange.Find.Format = False

' Here is new code to delete blank underlining at beginning of
underline.
' Unlike main code, this uses Selection not Range, but because it's
simpler it
' doesn't create the flashing problem caused by using Selection for
main task.

Application.ScreenUpdating = False
With Selection.Find
.ClearFormatting
.Text = ""
.Font.Underline = wdUnderlineSingle
.Forward = True
.Wrap = wdFindContinue

Do While .Execute
With Selection
If .Characters.First = " " Then _
.Characters.First.Font.Underline = wdUnderlineNone
.MoveRight wdCharacter, 1
End With
Loop
End With
' Runs macro (below) that removes underlining from under open quote
marks.
QuoteUnderlineRemove
r.Select

End Sub


Sub QuoteUnderlineRemove()

' Removes underlining from opening quote mark at beginning of underlined
' text. This is run from UnderlineRetract.

Application.Run "StartUndoSaver"
Application.ScreenUpdating = False
Dim r As Range
Set r = Selection.Range

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Underline = wdUnderlineSingle
With Selection.Find
.Text = """[A-Za-z]"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWildcards = True
Do While .Execute
With Selection
.MoveLeft wdCharacter, 1
.MoveLeft wdCharacter, 1, wdExtend
If .Font.Underline = wdUnderlineNone And .Text = " " Then
.MoveRight wdCharacter, 1
.MoveRight wdCharacter, 1, wdExtend
.Font.Underline = wdUnderlineNone
.MoveRight wdCharacter, 1
Else
.MoveRight wdCharacter, 2
End If
End With
Loop
End With
With Selection.Find
.Text = ""
.Format = False
.MatchWildcards = False
End With

End Sub
 
G

Graham Mayor

You need to put the cursor in the find or replace box before clicking CTRL+I
or U.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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