Thread: [Solved] Save Selection
View Single Post
 
Old 01-12-2011, 06:17 AM
cksm4 cksm4 is offline Windows XP Office 2007
Advanced Beginner
 
Join Date: Aug 2010
Posts: 48
cksm4 is on a distinguished road
Default

Hey Paul,

Thanks again for replying. I worked on this last night and made a little progress. As you can see below I set the selected text to a variable:

Selection.Find.ClearFormatting
With Selection.Find
.Text = "Level 1"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
vCatagory1 = Selection.Text
Selection.Collapse
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Level 2"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
vCatagory2 = Selection.Text
Selection.Collapse
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Level 3"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
vCatagory3 = Selection.Text
Selection.GoTo What:=wdGoToBookmark, Name:="IndexThis"
ActiveDocument.Indexes.MarkEntry Range:=Selection.Range, _
Entry:=vCatagory1 & ":" & vCatagory2 & ":" & vCatagory3, CrossReference:="", CrossReferenceAutoText:="", _
BookmarkName:="", Bold:=False, Italic:=False

This creates a three level index based on the values of the three fields. It works but I am back to the loop issue as this code needs to run for each document. My final document is a combination of mutiple forms (page breaks between) filled out by the user. I can run this code on each form as it is created, but I prefer to run it just once after the final combination is complete. I am struggling with the transition from the first search to the "Do While" and have not been able to get it to work.

Brock
Reply With Quote