Macro to change formatting: Help needed

G

Greg Purvis

Hi.

I want to make global changes in documents with a single macro.

It has to effect two replacements:

a) Underlined text > Bolded text and a specific color;
b) Bold/Underlined text > Bold and specific color.

I can effect these changes with the Find/Replace tool manually, but I'm
having trouble macro-recording those manual replacements.

I'm not yet familiar enough with VisualBasic to try the code manually.

Thanks for any helpful suggestions about how to do this.

GP
 
S

Shauna Kelly

Hi Greg
a) Underlined text > Bolded text and a specific color;
b) Bold/Underlined text > Bold and specific color.

Logically, you have to do them in the reverse order (b, then a). The
following code should do what you need. To change the colours, delete,
eg, " = wdColorGreen". Then type an equals sign and Word will pop up
all the valid colour choices from which you can choose. I've included
comments to show what the code is doing.

If you're not sure what to do with the macro, see
http://www.gmayor.dsl.pipex.com/installing_macro.htm and
http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm


Sub ChangeGregsFormatting()
'Shauna Kelly, 14 December 2003
'for microsoft.public.word.newusers
'
'Changes text that is bold + underline
'to bold + blue + no underline.
'Changes text that is underlined
'to bold + green + no underline.


'STEP 1: BOLD + UNDERLINED TO BOLD + BLUE

'Clean out left-over settings
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

With Selection.Find
'Set what to find
.Text = ""
With .Font
.Bold = True
.Underline = True
End With

'Set how to find it
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

'Set the replacement
With .Replacement
.Text = ""
With .Font
.Bold = True
.Color = wdColorBlue
.Underline = wdUnderlineNone
End With
End With

'Do the search and replace
.Execute Replace:=wdReplaceAll
End With

'STEP 2: UNDERLINED TO BOLD + GREEN

'Clean out left-over settings
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

With Selection.Find
'Set what to find
.Text = ""
.Font.Underline = True

'Set how to find it
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

'Set the replacement
With .Replacement
.Text = ""
With .Font
.Bold = True
.Color = wdColorGreen
.Underline = wdUnderlineNone
End With
End With

'Do the search and replace
.Execute Replace:=wdReplaceAll
End With


End Sub




Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Melbourne, Australia
 
G

Greg Purvis

----- Original Message -----
From: "Shauna Kelly" <[email protected]>
Newsgroups: microsoft.public.word.newusers
Sent: Sunday, December 14, 2003 12:32 AM
Subject: Re: Macro to change formatting: Help needed


[snip]
Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Melbourne, Australia


Thanks very much for the help. The comments in the code got me a couple of
good steps ahead in understanding VB too. Much appreciated.

Greg Purvis
Pembroke Ontario
 

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