Find and replace per style

J

João Correia

Hi, I'm wondering if somebody could help me to create a
macro that finds text writed in a style created by me
(let's say it "underlineStrong" or something) and
replaces it for the same text but between '' (I don't
knoe how to say this in English :), in portuguese
is 'plica').

Example: I have the text "John ate the cake" (whithout ")
in underlinestrong style and I want to replace it
for 'John ate the cake'.

Can somebody give me a light?

Thanks a lot!

João
 
J

Jay Freedman

João Correia said:
Hi, I'm wondering if somebody could help me to create a
macro that finds text writed in a style created by me
(let's say it "underlineStrong" or something) and
replaces it for the same text but between '' (I don't
knoe how to say this in English :), in portuguese
is 'plica').

Example: I have the text "John ate the cake" (whithout ")
in underlinestrong style and I want to replace it
for 'John ate the cake'.

Can somebody give me a light?

Thanks a lot!

João

Hi João,

Here's the macro you want. In the .Replacement.Text expression, the ^&
symbol means "the text that was found". I assume that after inserting the '
characters (in English, it's called either a single quote or an apostrophe)
you want to remove the character style, so the .Replacement.Style is set to
"Default Paragraph Font".

Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Wrap = wdFindStop
.Style = ActiveDocument.Styles("UnderlineStrong")
.Replacement.Text = "'^&'"
.Replacement.Style = _
ActiveDocument.Styles("Default Paragraph Font")
.Execute Replace:=wdReplaceAll
End With
 
J

João Correia

Hi, I'd like the style to remains underlineStrong because
it's the way I want the style works. I run the macro
after the user writes the text and it goes between single
quotes automatically. So, I don't need to call the
default paragraph font.

I don't know if this is the better way to do this, but I
don't know how to force characters like ' or ", to be in
my style.

A problem with the solutions Mr. Jay Freedman (Thanks a
lot) gave me is that the second single quote allways goes
to the next line, So I get something like 'my text
'

If somebody could help me with this, I would really
appreciate,

Thanks anyway,

João
-----Original Message-----


Hi João,

Here's the macro you want. In the .Replacement.Text expression, the ^&
symbol means "the text that was found". I assume that after inserting the '
characters (in English, it's called either a single quote or an apostrophe)
you want to remove the character style, so
the .Replacement.Style is set to
 
C

Chad DeMeyer

João,

Dim oRg as Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Wrap = wdFindStop
.Style = ActiveDocument.Styles("UnderlineStrong")
.Execute
Do While .Found = True
If Asc(Right(oRg.Text, 1)) = 13 Then
oRg.MoveEnd Unit:=wdCharacter, Count:=-1
oRg.InsertBefore "'"
oRg.InsertAfter "'"
oRg.MoveEnd Unit:=wdCharacter, Count:=1
.Execute
Loop
End With

Hope that helps
Regards,
Chad


Hi, I'd like the style to remains underlineStrong because
it's the way I want the style works. I run the macro
after the user writes the text and it goes between single
quotes automatically. So, I don't need to call the
default paragraph font.

I don't know if this is the better way to do this, but I
don't know how to force characters like ' or ", to be in
my style.

A problem with the solutions Mr. Jay Freedman (Thanks a
lot) gave me is that the second single quote allways goes
to the next line, So I get something like 'my text
'

If somebody could help me with this, I would really
appreciate,

Thanks anyway,

João
-----Original Message-----


Hi João,

Here's the macro you want. In the .Replacement.Text expression, the ^&
symbol means "the text that was found". I assume that after inserting the '
characters (in English, it's called either a single quote or an apostrophe)
you want to remove the character style, so
the .Replacement.Style is set to
 

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