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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Superscript in String 2

Status
Not open for further replies.

RP1America

Technical User
Aug 17, 2009
221
US
Greetings!

I am working in Word 2007 and would like a portion of string text to become superscript. Any ideas? Thanks!

I would like the "st" of 1st and 31st to be supersript.

Code:
strQuarterDates = "(January 1st through March 31st)"
 
Hi,

Strings do not have font properties.

Check out this example of a selection of (January 1st through March 31st) in your document...
Code:
    With Selection.Find
        .Execute FindText:="st"
        With Selection
            .Font.Superscript = True
        End With
    End With
and work with it.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Just make sure you don't superscript the 'st' in August.

If it will always be the 1st and last days of the months, then you could search for '1st', '28th', '29th', '30th' & '31st' and superscript the ending range (last 2 characters) in each found range
 
You could equally search for
#th
with the "MatchWildcards" Option set True.
This will onl search THs that are preceded by a number...
;-)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Good suggestion.

I don't know if it's my version or setup, but that doesn't seem to work for me. '#th' doesn't find anything in the string 'this path is the 5th'.

'[0-9]th' does work for me. (with wildcards on)

Note you will probably need to search for all of the following strings to make sure you cover every instance:

1st 2nd 3rd [0-9]th
 
'Inserts/overwrites given string at current selection and autoformats it
Public Sub Example(strText As String)

Dim wombat As Range
Set wombat = ActiveDocument.Range(Selection.Start, Selection.End)
wombat = strText
wombat.AutoFormat

End Sub
 
Of course, if you prefer Skip's version with a Selection already made containing the text, then:

Public Sub Example()
Selection.Range.AutoFormat
End Sub
 


strong simplicity ==> *

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I am still quite confused as to how to get this work properly.

How do I select the text once it is inserted?

Here is what I have, it obviously does not work, as I am missing a key ingredient.

Thanks for your help!!

Original code:
Code:
With Documents.Open(FolIn6 + "\401(k) FS LS Architect A2.doc")
    .Bookmarks("QYD").Range.Text = strDateText
    .Bookmarks("RT2").Range.Text = txtRT21
    .Bookmarks("RT1").Range.Text = txtRT11
    .SaveAs (FolOut6 + "\401(k) FS LS Architect A2.doc")
    .Close
End With

After adding Skip's suggestion (where I thought it might go)
Code:
With Documents.Open(FolIn6 + "\401(k) FS LS Architect A2.doc")
    .Bookmarks("QYD").Range.Text = strDateText
    With Selection.Find
        .Execute findtext:="st"
        With Selection.Font
            .Superscript = True
        End With
    End With
    .Bookmarks("RT2").Range.Text = txtRT21
    .Bookmarks("RT1").Range.Text = txtRT11
    .SaveAs (FolOut6 + "\401(k) FS LS Architect A2.doc")
    .Close
End With
 
<ahem> ... if you use my suggestion, then you get:

With Documents.Open(FolIn6 + "\401(k) FS LS Architect A2.doc")
With .Bookmarks("QYD").Range
.Text = strDateText
.AutoFormat
End With
.Bookmarks("RT2").Range.Text = txtRT21
.Bookmarks("RT1").Range.Text = txtRT11
.SaveAs (FolOut6 + "\401(k) FS LS Architect A2.doc")
.Close
End With
 
Ding, Ding, Ding!! We have a winner!

Thanks strongm!! Perfection!

Sorry strongm, I am quite new to the wonderful world of VB and really did not understand how/where to execute either code that you or Skip provided.

I really appreciate all of you knowledgable folks shedding light for us peons!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top