Reply
 
Thread Tools Display Modes
  #1   Report Post  
Arnica Arnica is offline
Junior Member
 
Posts: 0
Default Macro for several replacements in Word 2003

I'm trying to set up a macro (Word 2003) to do several replacements in a selection of my text with italics in the replacement field.

I.e. I have a certain number of words (non italic) that need to be replaced with another word in italic.

I recorded the sequence for one of the words (actually, these are names of notes that need to be translated and italicized, ALA, BSI, etc.), and then copied it for each word.

My problem is that the italics don't get inserted with the macro, though they appeared when I recorded it.

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "A"
.Replacement.Text = "LA"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

What do I need to add to get the italics?

Many thanks!
  #2   Report Post  
Arnica Arnica is offline
Junior Member
 
Posts: 0
Default

Quote:
Originally Posted by Arnica View Post
I'm trying to set up a macro (Word 2003) to do several replacements in a selection of my text with italics in the replacement field.

I.e. I have a certain number of words (non italic) that need to be replaced with another word in italic.

I recorded the sequence for one of the words (actually, these are names of notes that need to be translated and italicized, ALA, BSI, etc.), and then copied it for each word.

My problem is that the italics don't get inserted with the macro, though they appeared when I recorded it.

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "A"
.Replacement.Text = "LA"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

What do I need to add to get the italics?

Many thanks!
After further tries recording a macro with font attributes (italics), and seeing them disappear when I edit the macro itself, I just tried the same thing in Word 2000 and didn't have this problem. So I can solve the problem myself by adding the missing line. But is this a known bug in Word 2003? Or is there something that should be done differently?

Thanks!
  #3   Report Post  
JWeissmn JWeissmn is offline
Junior Member
 
Posts: 0
Default

Try removing this line:

Selection.Find.Replacement.ClearFormatting

which removes the italic formatting from your replacement text.
  #4   Report Post  
Arnica Arnica is offline
Junior Member
 
Posts: 0
Default

Quote:
Originally Posted by JWeissmn View Post
Try removing this line:

Selection.Find.Replacement.ClearFormatting

which removes the italic formatting from your replacement text.
Thank you. Indeed, that's what I was suspecting. But I nevertheless need to add the italics, since they aren't there to begin with:

Selection.Find.Replacement.Font.Italic = True

I got this line by recording the same macro in Word 2000. The mystery is why it doesn't appear when I record exactly the same thing in Word 2003, where I get this line instead:

Selection.Find.Replacement.ClearFormatting

Any explanation for this behavior?

Thanks.
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro in Word 2003 Joe McGuire Microsoft Word Help 2 August 30th 08 08:53 PM
Word 2003 macro jboudreau New Users 3 April 20th 08 06:24 PM
Multiple Replacements Tazzy via OfficeKB.com New Users 2 January 23rd 07 09:35 AM
WORD 2003 Macro Ian Microsoft Word Help 1 January 10th 07 03:14 PM
Word 2003 macro and SendToPringer Ron Mailmerge 0 January 30th 05 04:15 AM


All times are GMT +1. The time now is 02:30 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"