Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format text after using Find command...

Status
Not open for further replies.

Wrangler36

Technical User
Dec 5, 2005
24
0
0
US
I'm having a little trouble formatting some text in a Word document. I'm using the "Find" operation to find the first, and only, occurrence of some text.

The steps I need to carry out are:

1) Find the "Registered" trademark symbol
2) Set it as Superscript
3) Find the web address "4) Underline the web address and change the color to blue

The Registered trademark appears first in the document before the web address.

My problem: Word is finding the "Registered" trademark and performing the superscript, but it is also changing the color of the "Registered" trademark to blue and underlining it. For some reason it is performing the 1st part of the code on the "Registered" trademark and also performing the 2nd part of the code on the "Registered" trademark, when it should be performing the 2nd part of the code on the web address.

What am I missing? Here is the code I'm using which I obtained by recording a macro:

'Format the Registered trademark as superscript

Selection.Find.ClearFormatting
With Selection.Find
.Text = "®"
.Replacement.Text = ""
.Forward = True
End With
Selection.Find.Execute
With Selection.Font
.Superscript = True
End With

'Format web address as underline and change color to blue

Selection.Find.ClearFormatting
With Selection.Find
.Text = " .Replacement.Text = ""
.Forward = True
End With
Selection.Find.Execute
If Selection.Font.Underline = wdUnderlineNone Then
Selection.Font.Underline = wdUnderlineSingle
Else
Selection.Font.Underline = wdUnderlineNone
End If
Selection.Font.Color = wdColorBlue
 
Add the following between the first part and the second part.
Code:
Selection.Collapse Direction:=wdCollapseEnd
It should look like:
Code:
* * * * other stuff * * *
    With Selection.Font
        .Superscript = True
    End With
[COLOR=red]Selection.Collapse Direction:=wdCollapseEnd[/color red]
'Format web address as underline and change color to blue

    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "[URL unfurl="true"]www.mysite.com"[/URL]
        .Replacement.Text = ""
        .Forward = True
    End With
* * * * other stuff * * *

Gerry
 
Thanks fumei. That's what I was missing. It works now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top