Macro for Character Formatting

E

e125

Version of Word 2003:

I would like to know if someone can help me write a macro to do the following:

1) Find all instances of italicized text in a document
2) Replace it with Word's Emphasis Character formatting Style.

Any assistance would be much appreciated.
 
G

Greg Maxey

You don't need a macro to do this, but here it is:

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Font.Italic = True
.Replacement.Text = ""
.Replacement.Style = ActiveDocument.Styles("Emphasis")
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Execute Replace:=wdReplaceAll
End With
End Sub
 
E

e125

Thank you for the response. I tried running this macro and the following
error message came up: "Sub or Function not defined." I perform this
operation often, so any help would go a long way.

I originally requested help for this macro because my recorder button goes
dim the minute I call up the search and find dialog box. Otherwise I would go
about it this way.

Any help on both of these questions would be much appreciated.

e125
 
E

e125

I tinkered with the VBA a bit and found where the problem was. Thank you so
much for your help. this will save me tons of time.

Gratefully,
e125
 

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