Replace Italics with Bold in Word 2003 Macro

C

Charles Belov

I have the following code in which I am trying to replace italic formatting
in both the body text and headers/footers with bold:

Sub CleanUpItalics()
'
' CleanUpItalics Macro
' Macro recorded 11/14/2008 by cbelov
'
Call subCleanUpItalics
If ActiveWindow.Panes.Count > 1 Then
ActiveWindow.Panes(2).Activate
Call subCleanUpItalics
ActiveWindow.ActivePane.Close
End If
End Sub

Sub subCleanUpItalics()

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.ClearFormatting
.Text = "*"
.Font.Italic = True
.Replacement.Text = "^&"
.Replacement.Font.Italic = False
.Replacement.Font.Bold = True
.Execute Replace:=wdReplaceAll
.MatchWildcards = True
End With
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
End Sub

It accomplishes nothing.

How do I accomplish this replacement in a macro?

If I use <*> as the wildcard string the replacement happens, but that only
replaces the formatting for individual words. The space between them remains
italic. I'd like a clean document so that if I insert text within the
formerly italic area, the text will be bold, not italic regardless of where
I click.

<*> also doesn't work in the headers and footers (for the macro as coded
above).

Charles Belov
SFMTA
http://www.sfmta.com/webmaster
 
H

Helmut Weber

Hi Charles,

for a complete discussion of
"replace text where ever it appears in a document"
see e.g.:
http://word.mvps.org/faQs/Customization/ReplaceAnywhere.htm

from which I've taken the code posted here and modified it.
Which does not cover all possible complications,
but might be sufficient.

Sub ItalicToBold()
Dim rTmp As Range
For Each rTmp In ActiveDocument.StoryRanges
With rTmp.Find
.Font.Italic = True
While .Execute
rTmp.Font.Italic = False
rTmp.Font.Bold = True
rTmp.Collapse Direction:=wdCollapseEnd
Wend
End With
Next rTmp
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
K

Klaus Linke

With Selection.Find
.ClearFormatting
.Text = "*"
.Font.Italic = True


I think you may have forgotten (Selection.Find).Format=True ...

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Replacement.Font.Italic = False
Selection.Find.Replacement.Font.Bold = True
With Selection.Find
.Text = ""
.Replacement.Text = "^&"
.Format = True
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

I'd also add
.Forward = True
.Wrap = wdFindContinue
.... then you don't need to set up your search with
Selection.HomeKey Unit:=wdStory

Regards,
Klaus
 

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