Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Taking find and replace to another level

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vanessa - 11 Jan 2006 03:03 GMT
Hi all MS helpers!

I would like to be able to run the find and replace facility whereby parts
of the replacement text are either subscript or a different font size.  For
example replace TiO2 with TiO*2* (the *2* is either subscript or a smaller
font size).

Is it possible to add coding to the "replace" line or do I need to create a
macro?  I've never used Visual Basic, so I will probably need to be spoon fed
with the solution.

Thanking you,
Vanessa
Greg Maxey - 11 Jan 2006 04:50 GMT
Vanessa,

Doug Robbins and I (mostly Doug) worked on something for this a year so ago.
Say you want to replace H2O with the Hsubcript2O then in the first message
box that appears, type UP.  The rest is self explanatory in the prompts.

Sub Exponents()
Dim Message, Title, Default, Characterformat As String
Starthere:
 Message = "Enter Up for superscript; Down for Subscript"
 Default = "Up"
 Characterformat = UCase(InputBox(Message, Title, Characterformat))
 Message = "Enter the search pattern"    ' Set prompt.
 Title = "Search Pattern"    ' Set title.
 Default = "H2O2"    ' Set default.

GetInput:
   SearchString = InputBox(Message, Title, Default)
   If SearchString = "" Then
       End 'quit subroutine
   End If

Dim Message1, Title1, Default1, FirstScriptCharacter
   Message1 = "Counting from the left, enter the number of the first
script" _
   & " character" ' Set prompt."
   Title1 = "First Script Character"    ' Set title.
   Default1 = "2"    ' Set default.

GetInput1:
   FirstScriptCharacter = InputBox(Message1, Title1, Default1)

Dim Message2, Title2, Default2, SecondScriptCharacter
   Message2 = "Counting from the left, enter the number of the second
script character" ' Set prompt.
   Title2 = "Second Script Character"    ' Set title.
   Default2 = "4"    ' Set default.

GetInput2:
   SecondScriptCharacter = InputBox(Message2, Title2, Default2)

Dim Message3, Title3, Default3, ThirdScriptCharacter
   Message3 = "Counting from the left, enter the number of third script " _
   & " character" ' Set prompt."
   Title3 = "Third Script Character"    ' Set title.
   Default3 = ""    ' Set default.

GetInput3:
   ThirdScriptCharacter = InputBox(Message3, Title3, Default3)

Dim Message4, Title4, Default4, FourthScriptCharacter
   Message4 = "Counting from the left enter the number of the fourth script
" _
& "character " ' Set prompt."
   Title4 = "FourthScriptCharacter"    ' Set title.
   Default4 = ""    ' Set default.

GetInput4:
   FourthScriptCharacter = InputBox(Message4, Title4, Default4)

Dim myrange As Range
   Selection.HomeKey Unit:=wdStory
   Selection.Find.ClearFormatting
   With Selection.Find
      Do While .Execute(FindText:=SearchString, MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
         Set myrange = Selection.Range
         If Characterformat = "DOWN" Then
           If IsNumeric(FirstScriptCharacter) Then
myrange.Characters(FirstScriptCharacter).Font.Subscript = True
           If IsNumeric(SecondScriptCharacter) Then
myrange.Characters(SecondScriptCharacter).Font.Subscript = True
           If IsNumeric(ThirdScriptCharacter) Then
myrange.Characters(ThirdScriptCharacter).Font.Subscript = True
           If IsNumeric(FourthScriptCharacter) Then
myrange.Characters(FourthScriptCharacter).Font.Subscript = True
         ElseIf Characterformat = "UP" Then
           If IsNumeric(FirstScriptCharacter) Then
myrange.Characters(FirstScriptCharacter).Font.Superscript = True
           If IsNumeric(SecondScriptCharacter) Then
myrange.Characters(SecondScriptCharacter).Font.Superscript = True
           If IsNumeric(ThirdScriptCharacter) Then
myrange.Characters(ThirdScriptCharacter).Font.Superscript = True
           If IsNumeric(FourthScriptCharacter) Then
myrange.Characters(FourthScriptCharacter).Font.Superscript = True
         Else
           MsgBox "Invalid Entry. You must enter either Up or Down."
           GoTo Starthere
         End If
       Loop
   End With
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi all MS helpers!
>
[quoted text clipped - 9 lines]
> Thanking you,
> Vanessa
Doug Robbins - Word MVP - 11 Jan 2006 05:11 GMT
Your memory is better than mine<g>

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Vanessa,
>
[quoted text clipped - 104 lines]
>> Thanking you,
>> Vanessa
Greg Maxey - 11 Jan 2006 11:52 GMT
Sorry Sensei.  That comes with youth ;-)

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Your memory is better than mine<g>
>
[quoted text clipped - 112 lines]
>>> Thanking you,
>>> Vanessa
Graham Mayor - 11 Jan 2006 07:10 GMT
To replace TiO2 with a subscripted 2 you don't even need a macro. Type the
correct version. Copy that version with the subscripted 2 to the clipboard
then replace TiO2 with ^c throughout the document.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hi all MS helpers!
>
[quoted text clipped - 9 lines]
> Thanking you,
> Vanessa
Greg Maxey - 11 Jan 2006 11:50 GMT
Graham,

I dreamed about that method last night.  Just got up and returned here to
post. LOL

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> To replace TiO2 with a subscripted 2 you don't even need a macro.
> Type the correct version. Copy that version with the subscripted 2 to
[quoted text clipped - 13 lines]
>> Thanking you,
>> Vanessa
Graham Mayor - 11 Jan 2006 12:30 GMT
If you are dreaming about Word, you need that extra glass of JB to stop it
;)

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Graham,
>
[quoted text clipped - 18 lines]
>>> Thanking you,
>>> Vanessa
Greg - 11 Jan 2006 13:42 GMT
Never touch the stuff ;-)
Graham Mayor - 11 Jan 2006 13:59 GMT
Watch out for that lightning ;)

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Never touch the stuff ;-)
Vanessa - 12 Jan 2006 04:42 GMT
GM,

So kind of you to recall a previous response, dust off the cob webbs and
re-post for my benefit.  I'll give it a bash.  Not so keen on pasting correct
format of TiO2 over every incorrect instance though.

Graham, go have another JB and let Greg do all the work.

Cheers and sweet dreams guys

> Watch out for that lightning ;)
>
> > Never touch the stuff ;-)
Greg Maxey - 12 Jan 2006 05:55 GMT
Vanessa,

My good buddy Graham and I conjured up the replace with the content of the
clipboard long after the older forgetful gentleman Doug and I grunted our
way through this code.

Fact remains if you want to replace CO2 with COss2 once or a billion time
you can simply type COss2 once, copy it to the clipboard and then use the
standard Edit Replace dialog.

Type:  CO2 in the find what field
Type:  ^c in the replace with
press enter

Vanessa ... pretty name.  You have stirred an ember.  Never mind, I will go
back to the dream ;-)

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> GM,
>
[quoted text clipped - 17 lines]
>>
>>> Never touch the stuff ;-)
Graham Mayor - 12 Jan 2006 07:16 GMT
There never was an intention to paste over every instance. Replace does that
for you.
JB is Greg's tipple. I prefer Jack - or the local brandy here ;)

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> GM,
>
[quoted text clipped - 17 lines]
>>
>>> Never touch the stuff ;-)
Greg - 12 Jan 2006 06:08 GMT
Graham,

Stangest thing.  It was clear as a bell here today. I went out for
lunch and like a bolt out of the blue, BLAM!!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.