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 2005

Tip: Looking for answers? Try searching our database.

Numbering particular words in sentences contained in paragraphs

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dado_maker - 02 Jan 2005 22:27 GMT
For every occurance of a particular word in a paragraph, I would like to
subscript a number right before the word.
I need to increment a interger var for each occurance replace the word
with the subscript and word back into the sentence, and after leaving
the paragraph return the var to 1 for the next paragraph(s).

Any help appreciated,
dado_maker
Greg Maxey - 03 Jan 2005 00:57 GMT
dado_maker,

This seems to work if I understand your objective.  I am sure it is rough,
rough, rough and perhaps a master will be along to offer improvement.

Sub ScratchMacro()
Dim oPara As Paragraph
Dim oWord As Range
Dim i As Long
Dim myWord As String

myWord = InputBox("Enter the word to find.")

For Each oPara In ActiveDocument.Paragraphs
 i = 0
 For Each oWord In oPara.Range.Words
     If Right(oWord, 1) = " " Then oWord.MoveEnd Unit:=wdCharacter,
Count:=-1
     If LCase(oWord) = LCase(myWord) Then
       i = i + 1
       oWord.Collapse Direction:=wdCollapseStart
       oWord.Select
       'insert field, reset sequence to 1 for first occurence in paragraph
       If i = 1 Then
         Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
         "SEQ WordNum \r1", PreserveFormatting:=True
       Else
       'insert field
         Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
         "SEQ WordNum", PreserveFormatting:=True
       End If
       'superscript the sequence number
       Selection.MoveLeft Unit:=wdCharacter, Count:=1
       Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
       With Selection.Font
         .Superscript = True
       End With
     End If
  Next
Next

End Sub

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> For every occurance of a particular word in a paragraph, I would like
> to subscript a number right before the word.
[quoted text clipped - 4 lines]
> Any help appreciated,
> dado_maker
 
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.